-
-
Save jmettraux/5f716c8568f6ab7bb016a4bc11528bc2 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
# | |
# Question: | |
# How to check if rufus-scheduler is already running for my Rails Application? | |
# | |
def rufus_running?(s) | |
return false unless s.up? | |
return false unless s.thread.alive? | |
true | |
end | |
def is_rufus_scheduler_already_running_in_my_rails_application? | |
return false unless defined?(Rufus::Scheduler) | |
ObjectSpace.each_object do |o| | |
next unless o.is_a?(Rufus::Scheduler) | |
return true if rufus_running?(o) | |
end | |
false | |
end | |
alias rufus? is_rufus_scheduler_already_running_in_my_rails_application? | |
fail "rufus should not be running..." if rufus? == true | |
require 'rufus-scheduler' | |
fail "rufus should not be running..." if rufus? == true | |
s = Rufus::Scheduler.new | |
fail "rufus should be running..." if rufus? == false | |
s.thread.exit | |
sleep 0.4 | |
fail "rufus should not be running..." if rufus? == true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment