Class: Eye::Process

Inherits:
Object show all
Extended by:
Validate
Includes:
Celluloid, Children, Commands, Config, Controller, Data, Monitor, Notify, Scheduler, System, Trigger, Watchers
Defined in:
lib/eye/process.rb,
lib/eye/process/states.rb

Defined Under Namespace

Modules: Children, Commands, Config, Controller, Data, Monitor, Notify, Scheduler, System, Trigger, Validate, Watchers Classes: StateError, StatesHistory

Constant Summary

Constants included from Notify

Notify::LEVELS

Constants included from Config

Config::DEFAULTS

Instance Attribute Summary collapse

Attributes included from Scheduler

#current_scheduled_command, #last_scheduled_at, #last_scheduled_command, #last_scheduled_reason

Instance Method Summary collapse

Methods included from Validate

validate

Methods included from Scheduler

included, #schedule, #schedule_history, #schedule_in, #scheduled_action, #scheduler_actions_list, #scheduler_clear_pending_list

Methods included from Notify

included, #notify, #notify_died

Methods included from Trigger

#add_triggers, #check_triggers, #remove_triggers, #retry_start_after_flapping

Methods included from Children

#add_children, #add_or_update_children, #remove_child, #remove_children

Methods included from System

#clear_pid_file, #execute, #failsafe_load_pid, #failsafe_save_pid, #load_pid_from_file, #pid_file_ctime, #process_pid_running?, #process_really_running?, #save_pid_to_file, #send_signal, #set_pid_from_file, #wait_for_condition

Methods included from Watchers

#add_watchers, #remove_watchers

Methods included from Controller

#delete, #monitor, #restart, #send_command, #signal, #start, #stop, #unmonitor

Methods included from Commands

#restart_process, #start_process, #stop_process

Methods included from Data

#app_name, #debug_data, #environment_string, #full_name, #group_name, #group_name_pure, #logger_tag, #self_status_data, #shell_string, #status_data, #sub_object?

Methods included from Config

#[], #c, #control_pid?, #prepare_config, #update_config

Constructor Details

#initialize(config) ⇒ Process

Returns a new instance of Process.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eye/process.rb', line 24

def initialize(config)
  raise 'you must supply a pid_file location' unless config[:pid_file]

  @config = prepare_config(config)

  @watchers = {}
  @children = {}
  @triggers = []
  @name = @config[:name]

  @flapping_times = 0

  @states_history = Eye::Process::StatesHistory.new(100)
  @states_history << :unmonitored

  debug "creating with config: #{@config.inspect}"

  add_triggers

  super() # for statemachine
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



20
21
22
# File 'lib/eye/process.rb', line 20

def children
  @children
end

#configObject

Returns the value of attribute config.



20
21
22
# File 'lib/eye/process.rb', line 20

def config
  @config
end

#flapping_timesObject

Returns the value of attribute flapping_times.



20
21
22
# File 'lib/eye/process.rb', line 20

def flapping_times
  @flapping_times
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/eye/process.rb', line 20

def name
  @name
end

#parent_pidObject

Returns the value of attribute parent_pid.



20
21
22
# File 'lib/eye/process.rb', line 20

def parent_pid
  @parent_pid
end

#pidObject

Returns the value of attribute pid.



20
21
22
# File 'lib/eye/process.rb', line 20

def pid
  @pid
end

#state_reasonObject

Returns the value of attribute state_reason.



20
21
22
# File 'lib/eye/process.rb', line 20

def state_reason
  @state_reason
end

#states_historyObject

Returns the value of attribute states_history.



20
21
22
# File 'lib/eye/process.rb', line 20

def states_history
  @states_history
end

#triggersObject

Returns the value of attribute triggers.



20
21
22
# File 'lib/eye/process.rb', line 20

def triggers
  @triggers
end

#watchersObject

Returns the value of attribute watchers.



20
21
22
# File 'lib/eye/process.rb', line 20

def watchers
  @watchers
end

Instance Method Details

#log_transition(transition) ⇒ Object



79
80
81
82
83
84
# File 'lib/eye/process/states.rb', line 79

def log_transition(transition)
  if transition.to_name != transition.from_name || @state_reason.is_a?(Eye::Reason::User)
    @states_history.push transition.to_name, @state_reason
    info "switch :#{transition.event} [:#{transition.from_name} => :#{transition.to_name}] #{@state_reason ? "(reason: #{@state_reason})" : nil}"
  end
end

#on_crashedObject



71
72
73
# File 'lib/eye/process/states.rb', line 71

def on_crashed
  schedule :check_crash, Eye::Reason.new(:crashed)
end

#on_unmonitoredObject



75
76
77
# File 'lib/eye/process/states.rb', line 75

def on_unmonitored
  self.pid = nil
end

#switch(name, reason = nil) ⇒ Object

do transition



8
9
10
11
# File 'lib/eye/process/states.rb', line 8

def switch(name, reason = nil)
  @state_reason = reason || last_scheduled_reason
  self.send("#{name}!")
end