Skip to content

Instantly share code, notes, and snippets.

@richcorbs
Last active December 15, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richcorbs/5220305 to your computer and use it in GitHub Desktop.
Save richcorbs/5220305 to your computer and use it in GitHub Desktop.
Rufus scheduler single cron, multiple "tasks", with and without mutex
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.start_new
# without mutex
scheduler.cron '*/1 * * * *' do
puts '1'
sleep 10
puts '2'
sleep 5
puts '3'
end
# with mutex
# scheduler.cron '*/1 * * * *', :mutex => 'my_mutex' do
# puts '1'
# sleep 10
# puts '2'
# sleep 5
# puts '3'
# end
scheduler.join
# OUTPUT FOR BOTH
1
# 10 second pause
2
# 5 second pause
3
# 45 second pause
1
# 10 second pause
2
# 5 second pause
3
# 45 second pause
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment