Skip to content

Instantly share code, notes, and snippets.

@kinnalru
Last active January 15, 2021 13:12
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 kinnalru/6bdfa3f7eff04213f639cf9c80c427b9 to your computer and use it in GitHub Desktop.
Save kinnalru/6bdfa3f7eff04213f639cf9c80c427b9 to your computer and use it in GitHub Desktop.
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