'Is it possible to reset the timeout of a delayed job in rails?
I have a delayed job that run a few steps. I would like to reset the timeout whenever a step is completed.
Is it possible?
For example
# config/initializers/delayed_job_config.rb
Delayed::Worker.max_run_time = 5.minutes
# app/jobs/my_process_job.rb
class MyProcessJob < ApplicationJob
def perform
`sleep 4m` # step 1
# reset timeout
`sleep 4m` # step 2
puts 'done'
end
end
Solution 1:[1]
Looking at how timeouts are implemented in Delayed Job, it's not possible to reset the timeout without modifying Delayed Job. However, you could do the following instead
# config/initializers/delayed_job_config.rb
Delayed::Worker.max_run_time = 10.minutes
# app/jobs/my_process_job.rb
class MyProcessJob < ApplicationJob
def perform
Timeout.timeout(5.minutes.to_i) {
`sleep 4m` # step 1
}
Timeout.timeout(5.minutes.to_i) {
`sleep 4m` # step 2
}
puts 'done'
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cameron |
