Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Last active April 3, 2017 07:23
Show Gist options
  • Save jmettraux/5f716c8568f6ab7bb016a4bc11528bc2 to your computer and use it in GitHub Desktop.
Save jmettraux/5f716c8568f6ab7bb016a4bc11528bc2 to your computer and use it in GitHub Desktop.
#
# 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