Ruby on Rails Delayed Job Local Wont Run

邮差的信 提交于 2019-12-01 04:58:40

问题


I'm working with delayed job for active record gem https://github.com/collectiveidea/delayed_job I'm trying to set up a job to run five minutes after an event occurs in my application. After five minutes passes, I need to make some database updates. I've tried rake jobs:work and RAILS_ENV=development script/delayed_job start. Prior to this all, I have run bundle install, rails generate delayed_job:active_record, and rake db:migrate. I have a lottery website that needs to check winners every five minutes and update tokens for winning players.

I wait five minutes, but no updates are made in my local application.

Here's what I have so far:

Gem File:

 gem 'delayed_job_active_record'

 gem "daemons"

Job (located in lib)

class WinnersJob < Struct.new(:blast_id)
def perform
      ...
    end

Controller

 require 'winners'
 Delayed::Job.enqueue(WinnersJob.new(blast.id), 1, 5.minutes.from_now)
 end

回答1:


I think you have to launch the background workers locally using foreman. The following worked on my Mac.

From Heroku docs:

You then need to tell your application to process jobs put into your job queue, you can do that by adding this to your Procfile:

worker:  bundle exec rake jobs:work

Now when you start your application using Foreman it will start processing your job queue.

foreman start

Having said all that, unless you are deploying on a Mac, it doesn't really matter if they run locally. (I noticed this after I got it working.) It only matters if it works on your servers. If you are deploying on Heroku, then Delayed Job works well.

Reference:

https://devcenter.heroku.com/articles/delayed-job
https://devcenter.heroku.com/articles/procfile



来源:https://stackoverflow.com/questions/13416439/ruby-on-rails-delayed-job-local-wont-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!