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

Instance Method Summary collapse

Methods included from Validate

validate

Methods included from Scheduler

#ensure_scheduler_process, #equal_action_call?, #filter_call, #internal_schedule, #schedule, #scheduler_add, #scheduler_calls, #scheduler_clear_pending_list, #scheduler_commands_list, #scheduler_consume, #scheduler_current_command, #scheduler_history, #scheduler_last_command, #scheduler_last_reason, #scheduler_run, #send_call, #user_schedule

Methods included from Notify

#notify

Methods included from Trigger

#add_triggers, #check_triggers, #conditional_start, #remove_triggers

Methods included from Children

#add_children, #add_or_update_children, #clear_child, #remove_child, #remove_children

Methods included from System

#clear_pid_file, #compare_identity, #daemonize, #execute, #execute_async, #execute_sync, #expand_path, #failsafe_load_pid, #failsafe_save_pid, #get_identity, #load_pid_from_file, #pid_file_ctime, #process_pid_running?, #process_really_running?, #save_pid_to_file, #send_signal, #wait_for_condition

Methods included from Watchers

#add_watchers, #remove_watchers

Methods included from Controller

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

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?, #timers_data

Methods included from Config

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

Constructor Details

#initialize(config) ⇒ Process

Returns a new instance of Process.



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

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]

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

  @state_call = {}

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

  add_triggers

  super() # for statemachine
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



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

def children
  @children
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#parent_pidObject

Returns the value of attribute parent_pid.



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

def parent_pid
  @parent_pid
end

#pidObject

Returns the value of attribute pid.



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

def pid
  @pid
end

#state_reasonObject

Returns the value of attribute state_reason.



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

def state_reason
  @state_reason
end

#states_historyObject

Returns the value of attribute states_history.



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

def states_history
  @states_history
end

#triggersObject

Returns the value of attribute triggers.



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

def triggers
  @triggers
end

#watchersObject

Returns the value of attribute watchers.



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

def watchers
  @watchers
end

Instance Method Details

#log_transition(transition) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/eye/process/states.rb', line 81

def log_transition(transition)
  if transition.to_name != transition.from_name || @state_call[:by] == :user
    reason_str = reason_from_call(@state_call)
    @states_history.push transition.to_name, reason_str
    info "switch :#{transition.event} [:#{transition.from_name} => :#{transition.to_name}] #{reason_str}"
  end
end

#on_crashedObject



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

def on_crashed
  self.pid = nil
  schedule command: :check_crash, reason: :crashed
end

#on_unmonitoredObject



77
78
79
# File 'lib/eye/process/states.rb', line 77

def on_unmonitored
  self.pid = nil
end

#switch(name, call = {}) ⇒ Object

do transition



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

def switch(name, call = {})
  @state_call = @last_scheduled_call ? @last_scheduled_call.merge(call) : call
  self.send("#{name}!")
end