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.
- Query for the jobs that failed
- Then update the
run_at
toTime.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
How to Use Ruby Dbi's 'Select_All' VS 'Execute-Fetch/Each-Finish'
Is Every Relavant Calculation Performed Every Time the Page Is Loaded
Strip Signatures and Replies from Emails
Rails Active Record Find(:All, :Order => ) Issue
In Ruby, What Is the Cleanest Way of Obtaining the Index of the Largest Value in an Array
Rails 3/Ruby: Activerecord Find Method in Condition Array to Parameters Single Quote Issue
How to Disable Mongodb Log Messages in Console
How to Call a Super Class Method
Check If User Is Active Before Allowing User to Sign in with Devise (Rails)
Convert Non-Ascii Chars from Ascii-8Bit to Utf-8
How to Reference a File from Inside of a Gem
How to Fix a Deadlock Caused by Open
How to Log Every Method That's Called in a Ruby Program
Ruby Method Calls Declared in Class Body
When Do We Use the "||=" Operator in Rails? What Is Its Significance
Rails Authentication Across Apps/Servers
What Does ':Location => ...' and 'Head :Ok' Mean in the 'Respond_To' Format Statement