开发者

For Ruby on Rails, how do you use delayed_job (and add generator)?

This is for http://github.com/tobi/delayed_job

the example says:

script/generate delayed_job_migration

if I run it

$ script/generate delayed_job_migration
Couldn't find 'delayed_job_migration' generator

On github, there is a generators folder, an init.rb, a lib folder, and a tasks folder, where should they go into our project? (using Rails 3.0)

It also says add code like this:

class NewsletterJob &l开发者_运维知识库t; Struct.new(:text, :emails)
  def perform
    emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
  end    
end  

Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email))

but where should this code go? to the controller or in a lib file? and how do you invoke it? I suppose the enqueue code need to only run once really?


Try the collective idea delayed_job http://github.com/collectiveidea/delayed_job . I think it is more complete, I have used it and I had no problem.

1) Just install

2) run the migration

3) start the workers with the command

rake jobs:work

4) put inside the controller the command with the delay. For example @video.delay.convert

And you are ready.

Sometimes you might need to restart the workers to take effect the new changes you made.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜