Sha256: 8f4592ab5fdeb5532af69ff00bc8bf11008128dff92ec9c6197cca19850c2c0b
Contents?: true
Size: 1.48 KB
Versions: 24
Compression:
Stored size: 1.48 KB
Contents
require "active_support/concern" module RocketJob class Server # State machine for sliced jobs module StateMachine extend ActiveSupport::Concern included do # States # :starting -> :running -> :paused # -> :stopping aasm column: :state, whiny_persistence: true do state :starting, initial: true state :running state :paused state :stopping event :started do transitions from: :starting, to: :running before do self.started_at = Time.now build_heartbeat(updated_at: Time.now, workers: 0) end end event :pause do transitions from: :running, to: :paused end event :resume do transitions from: :paused, to: :running end event :stop do transitions from: :running, to: :stopping transitions from: :paused, to: :stopping transitions from: :starting, to: :stopping end end # Stop all running, paused, or starting servers def self.stop_all where(:state.in => %i[running paused starting]).each(&:stop!) end # Pause all running servers def self.pause_all running.each(&:pause!) end # Resume all paused servers def self.resume_all paused.each(&:resume!) end end end end end
Version data entries
24 entries across 24 versions & 1 rubygems