Manually Retry Job in Delayed_Job

Manually Retry Job in Delayed_job

To manually call a job

Delayed::Job.find(10).invoke_job # 10 is the job.id

This does not remove the job if it is run successfully. You need to remove it manually:

Delayed::Job.find(10).destroy

How to check if the delayed job is actually retrying

You can check:

Delayed::Job.find(id).attempts

attempts should show you haw many attempts it tried to do and if it reached the maximum it will stop trying.

Make sure you are not catching the error some where, otherwise the Delayed job will think its success and will be removed from the table.

Rerun errored delayed jobs

This question may help you. Check out steakchasers comment.

Looks like the ticket is a two step process.

  1. Query for the jobs that failed
  2. Then update the run_at to Time.now

Delayed Job: How to retrieve and update a scheduled job?

You can simply work on the Delayed::Job model (say activerecord if you use delayed_job_active_record)

The question is what job you want to retrieve, and how you take care of that.
No matter how you manage your jobs for later retrieval, you should use something like:

# submit the job and remember id
job_id_remember_for_later = Delayed::Job.enqueue(job).id
#...
# later
job = Delayed::Job.find_by_id(job_id_remember_for_later)
job.update_attributes(:run_at => new_time, :attempts => 0)
job.save

This code is surely unsafe, you need to check lock, etc.
Also note that you need to config delayed_job to keep failed jobs (deleted by default after max_attempts failures).

Delayed::Worker.destroy_failed_jobs = false

How do you tell a specific Delayed::Job to run in console?

answering how to run specific job from console:

Delayed::Job.find(x).invoke_job

but you must remember that it won't run any other things like destroying job that was done or so on. just running the job/task.

Queueing in Delayed_Job with ActiveJobs

You'll have to add some logic before RunReportsJob.perform_later(param1, param2, param3) to check for an already queued job priority and increase the priority number (lower number is higher priority according to documentation) in this example the queue:

highest_priority = Delayed::Job.where(queue: :RunReports).maximum(:priority)
Delayed::Worker.default_priority = highest_priority + 1 if highest_priority

RunReportsJob.perform_later(param1, param2, param3)

DelayedJob uses a table to save all the jobs info check the documentation at https://github.com/collectiveidea/delayed_job#gory-details



Related Topics



Leave a reply



Submit