This stuff is a bit similar to flask's apscheduler and crontab under Linux. If you want to use it, you need to install the rufus-scheduler dependency first.
gem install rufus-scheduler
Then write the scheduled task (if you want to run the script directly, remember to add scheduler.join at the end to take effect) .
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.new
scheduler.in '20m' do
# after 20 minutes
puts "hello world 1"
end
scheduler.at 'Thu Mar 26 07:31:43 +0900 2009' do
# at the appointed time
puts 'hello world 2'
end
scheduler.cron '0 22 * * 1-5' do
# every day of the week at 22:00 (10pm)
puts 'hello world 3'
end
scheduler.every '5m' do
# every 5 minutes
puts 'hello world 4'
end
scheduler.join