Simple scheduler that runs periodically.
Code is Really Simple.
scheduler = Rufus::Scheduler.start_new scheduler.in '20m' do puts "order ristretto" end
The Usage is Really Simple In Rails Environment. I'll take the example of Rake task First. I will try to create a resque:work like task.
task :my_scheduler_work => :environment do scheduler = Rufus::Scheduler.start_new scheduler.in '20m' do User.call_some_method end end
Doing This in an non rails Env.
For Ex: abcd.rake
require 'rake' # require 'abcd' # File with all the classes and libs that are needed for rake task to run. task :my_scheduler_work do scheduler = Rufus::Scheduler.start_new puts "scheduler is Running on PORT: #{$$}" scheduler.in '20m' do Acall_some_method end end
Once you run the Rake Task U will see that, this will work endlessly.
puts "scheduler is Running on PORT: #{$$}"
This will print the port number on which the scheduler is Running.
Finally run the rake task from the folder where u are developing the app.
bundle exec rake my_scheduler_work
Thats It. I think, tats enough for basic understanding.
Click the following link for more details: [Rufus-Scheduler][1]
[1]: https://github.com/jmettraux/rufus-scheduler