Reputation: 3264
I have a form when user can set day in week and time period (for example Monday from 02:00 to 03:00). Then I want to run specific method (periodically, for example every 30 seconds) but only during given time interval (it should be performed on background every Monday during 02:00 and 03:00, every 30 seconds). Is it possible to do this when time interval is created dynamically (by user)?
Upvotes: 0
Views: 1381
Reputation: 2518
You could define a cron job which runs a rake task (refer to this for syntactic sugar: https://github.com/javan/whenever). Your rake task could run every X seconds and query the database for new jobs.
However, calling a rake task via cron boots the rails app every time, so a more suffisticated approach would be to use sidekiq (http://sidekiq.org/) in combination with sidekiq-scheduler (https://github.com/moove-it/sidekiq-scheduler).
Upvotes: 1