3

Is there any way to pause and resume long task of delayed_job in rails. In my case a task is sending few hundreds of text messages using twilio. I want to give permission to my users to pause and resume the text message sending progress. Is it possible? Please let me know.

1 Answers1

2

There's, unfortunately, no built-in way to pause and resume jobs with delayed_job. See the following GitHub issue: https://github.com/collectiveidea/delayed_job/issues/58

This is not to say you can't accomplish this with additional work. You could have you job periodically check your database to see if it should wait before continuing. Defining how to accomplish "waiting" is another story. More than likely, you best bet is to design a way for the "pause" action to stop the current job and save its state. "Resuming" would then fire up another job that continues where it left off.

Marc Baumbach
  • 10,323
  • 2
  • 30
  • 45
  • Thanks. I have designed a way to define state of the job for my requirements to resume or re-schedule. But I am facing problem to stop a running job. Is there any way to stop a specific running job of delayed_job? – Maruf Hasan Bulbul Feb 07 '13 at 06:03
  • @MarufHasan I think you'd go with a similar approach there. Make the running job periodically check it's current state and if it's been told to stop, just stop executing the remaining portion of the job and probably call `destroy` on the ActiveRecord object that represents the delayed_job. This question discusses deleting those delayed_job objects: http://stackoverflow.com/questions/3638250/how-to-cancel-scheduled-job-with-delayed-job-in-rails – Marc Baumbach Feb 07 '13 at 14:37