开发者

Delayed_job : defining time

So I'm trying to figure out how to do this cleanly. Trying to keep the example simple lets say I have an object, MyMailMeeting in which I define two times that I want to send two different emails to people in a meeting.

In my MyMailMeeting model, I want to define both methods (rather than having their own delayed job class), but I need to have those methods see the times defined within the object in order to know when to send.

def send_first
  ... do stuff
end
handle_asynchronously :send_first, :run_at => Proc.new { send_first_time }

Problem is that according to the documentat开发者_如何学Goion, send_first_time needs to be a class method, and want it to be an instance method so that I can see the times defined by the user.

How do I do this? Or do I just need to create two separate Delayed_job classes and do something like this:

Delayed::Job.enqueue(SendFirstJob.new, :run_at => send_first_time)


I believe that handle_asynchronously passes the object into Procs for its attributs so:

handle_asynchronously :send_first, :run_at => Proc.new { |obj| obj.send_first_time }

You can always roll your own async wrapper

def send_first_async(*args)
  delay(:run_at => send_first_time).send_first(*args)
end


I ended up using the second method. Though it isn't as time sensitive as I would like.

If anyone has an answer on how to get send_first_time to be a variable that is based on user input, I'll gladly accept it as the right answer. Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜