polling with delayed_job

Let’s start with the API. I’d like to have something like the following. @available.working? # => true or false, so we know it’s running @available.finished? # => true or false, so we know it’s finished (already ran) Now let’s write the job. class AwesomeJob < Struct.new(:options) def perform do_something_with(options[:var]) end end So far so good. … Read more

Starting delayed_job at startup

In combination with the capistrano restart recipe it’s quite convenient to use cron to also start the delayed_job daemon at startup using the special @reboot time in a crontab: @reboot /bin/bash -l -c ‘cd /path/to/app && RAILS_ENV=production script/delayed_job restart’ And it’s even more convenient together with whenever to configure a scheduled task: job_type :envcommand, ‘cd … Read more

How to resolve deserialization error in delayed job?

It’s not really a deserialization error, it’s an ActiveRecord record-not-found error on a simple Model.find(id) query. If you want to know the details, log them in the delayed_job-2.1.3/lib/delayed/serialization/active_record.rb file, in the rescue statement, just before delayed-job stupidly raises the DeserializationError and throws the useful information away.

How to cancel scheduled job with delayed_job in Rails?

disclaimer: I am not an expert user of delayed_job… “Is there any call to remove particular job, or jobs related to specific model, instance, etc?“ Delayed::Job is just an ActiveRecord object so you can find and destroy any of those records. Depending on your use case this could be handled different ways. If someone is … Read more

Logging in delayed_job?

When I needed log output from Delayed Jobs, I found this question to be fairly helpful. In config/initializers/delayed_job.rb I add the line: Delayed::Worker.logger = Logger.new(File.join(Rails.root, ‘log’, ‘dj.log’)) Then, in my job, I output to this log with: Delayed::Worker.logger.info(“Log Entry”) This results in the file log/dj.log being written to. This works in development, staging, and production … Read more

How can I see the delayed job queue?

DelayedJob stores a database record for each enqueued job so you can retrieve them directly through the rails console (assuming you are using ActiveRecord or similar). Open the rails console: $ rails c and then query the enqueued jobs: Delayed::Job.all or Delayed::Job.last Check out the documentation. If you installed delayed_job with another database like Redis … Read more

How to monitor delayed_job with monit

Here is how I got this working. Use the collectiveidea fork of delayed_job besides being actively maintained, this version has a nice script/delayed_job daemon you can use with monit. Railscasts has a good episode about this version of delayed_job (ASCIICasts version). This script also has some other nice features, like the ability to run multiple … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)