I am using delayed_job and delayed_job_active_record for back ground job execution in my rails application. We are using queue based delayed_job. For starting the delayed I am using the following command.
RAILS_ENV=staging script/delayed_job -i=1 --queue=queue_name start
The problem is below query is firing infinitely.
SQL (0.4ms) UPDATE `delayed_jobs` SET `locked_at` = '2013-04-16 09:27:23', `locked_by` = 'delayed_job.=2 host:ip-10-204-210-77 pid:2168' WHERE `delayed_jobs`.`queue` IN ('queue_name') AND ((run_at <= '2013-04-16 09:27:23' AND (locked_at IS NULL OR locked_at < '2013-04-16 05:27:23') OR locked_by = 'delayed_job.=2 host:ip-10-204-210-77 pid:2168') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
And the delayed_job count is zero. Because of this the application is very slow and the pages are not loading in many places.
I think what you meant is that delayed_job
polls too frequently (which by the way is every 5
seconds by default) - I know that fills up your log, and seems "infinite".. :)
If that is what you meant, then I suggest you run the workless gem. It will only start delayed_job
on a per need basis. Many people use it to keep their Heroku worker dynos from running idle, but it works just as well in development
mode.
Note that if you are using delayed_job_active_record, you also need to add gem 'daemons'
to your Gemfile
(daemons). See the Running Jobs section of delayed_job
.
Thus, your Gemfile
would contain:
gem 'delayed_job_active_record'
gem 'daemons'
gem 'workless'
If you need more guidance, let me know in the comments below.
i had to use AR's silence
method, just change in file [path/to/delayed_job_active_record/gem]/delayed_job_active_record-[any.latest.version]/lib/delayed/backend/active_record.rb
around line 68:
count = ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)
to
count = silence {ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)}
dirty solution, i know, but it works... welcome to propose a better wrapper, but for me Job.reserve
method there is big enough to kill any thoughts to override it in config/initializers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With