Last active
January 15, 2021 13:12
-
-
Save kinnalru/6bdfa3f7eff04213f639cf9c80c427b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rufus-scheduler' | |
require 'lusnoc/mutex' | |
mutex = Lusnoc::Mutex.new('/locks/jobs', ttl: 20) | |
mutex.synchronize(timeout: 10) do |mx| | |
scheduler = Rufus::Scheduler.new.tap do |s| | |
mx.on_mutex_lost do | |
exit!(1) | |
end | |
s.every '10s' do | |
mx.renew | |
end | |
s.in '1h' do | |
RefreshCurrencyJob.perform_later | |
end | |
end | |
sleep 5 while scheduler.up? && mx.alive? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment