Reputation: 2053
I need to schedule a job in rails, where a method will called on a model. I know there are several cron-based gems, but these are all for repeating jobs, where as I need to perform the job only once, at a set time. Is there a gem that will do this?
Upvotes: 5
Views: 2607
Reputation: 10952
Rails 4.2 will have the Active Job framework for scheduling jobs. You can use the Active Job gem in Rails 4.1. It serves as a standardized wrapper for several queueing systems, including Sidekiq and Resque (both require Redis to handle delayed jobs). Using Active Job gives you the flexibility of swapping out the queueing system if necessary.
You can schedule a job with Active Job like this:
MyJob.enqueue_at(5.hours.from_now, record)
The Rails maintainers intend for this to become the standard mechanism for scheduling jobs.
Have a look at the rails-mailinglist-signup example application to see how to use Active Job.
Upvotes: 4
Reputation: 2576
If you deploy to Heroku, there is a scheduler add-on.
Otherwise, you can use Sidekiq + Sidetiq to accomplish what you are looking for.
Upvotes: 0