Skip to content

Instantly share code, notes, and snippets.

@entombedvirus
Created October 3, 2009 23:26
Show Gist options
  • Save entombedvirus/200977 to your computer and use it in GitHub Desktop.
Save entombedvirus/200977 to your computer and use it in GitHub Desktop.
state_machine :initial => :unmonitored do
state :unmonitored, :up, :down
event :tick do
transition :unmonitored => :unmonitored
transition [:up, :down] => :up, :if => :process_running?
transition [:up, :down] => :down, :unless => :process_running?
end
event :start do
transition :unmonitored => :up, :if => lambda {|process| process.process_running? || process.start_process }
transition :up => :up
transition :down => :up, :if => :start_process
end
event :stop do
transition [:unmonitored, :down] => :unmonitored
transition :up => :unmonitored, :if => :stop_process
end
event :restart do
transition all => :up, :if => :restart_process
end
event :unmonitor do
transition all => :unmonitored
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment