Class: Eye::Group

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Chain, Logger::Helpers, Process::Scheduler
Defined in:
lib/eye/group.rb

Defined Under Namespace

Modules: Chain

Instance Attribute Summary collapse

Attributes included from Process::Scheduler

#current_scheduled_command, #last_scheduled_at, #last_scheduled_command, #last_scheduled_reason

Attributes included from Logger::Helpers

#logger

Instance Method Summary collapse

Methods included from Process::Scheduler

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

Constructor Details

#initialize(name, config) ⇒ Group

Returns a new instance of Group.



14
15
16
17
18
19
20
21
# File 'lib/eye/group.rb', line 14

def initialize(name, config)
  @name = name
  @config = config
  @logger = Eye::Logger.new(full_name)
  @processes = Eye::Utils::AliveArray.new
  @hidden = (name == '__default__')
  debug 'created'
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/eye/group.rb', line 12

def config
  @config
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



12
13
14
# File 'lib/eye/group.rb', line 12

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/eye/group.rb', line 12

def name
  @name
end

#processesObject (readonly)

Returns the value of attribute processes.



12
13
14
# File 'lib/eye/group.rb', line 12

def processes
  @processes
end

Instance Method Details

#add_process(process) ⇒ Object



32
33
34
# File 'lib/eye/group.rb', line 32

def add_process(process)
  @processes << process
end

#break_chainObject



110
111
112
113
114
# File 'lib/eye/group.rb', line 110

def break_chain
  info "break chain"
  scheduler.clear_pending_list
  @chain_breaker = true    
end

#clearObject



116
117
118
# File 'lib/eye/group.rb', line 116

def clear
  @processes = Eye::Utils::AliveArray.new
end

#debug_dataObject



64
65
66
# File 'lib/eye/group.rb', line 64

def debug_data
  {:queue => scheduler_actions_list, :chain => chain_status}
end

#deleteObject



93
94
95
96
# File 'lib/eye/group.rb', line 93

def delete
  async_schedule :delete
  terminate
end

#full_nameObject



23
24
25
# File 'lib/eye/group.rb', line 23

def full_name
  @full_name ||= "#{@config[:application]}:#{@name}"
end

#monitorObject



98
99
100
# File 'lib/eye/group.rb', line 98

def monitor
  chain_command :monitor
end

#resort_processesObject

sort processes in name order



37
38
39
# File 'lib/eye/group.rb', line 37

def resort_processes
  @processes = @processes.sort_by(&:name)
end

#restartObject



89
90
91
# File 'lib/eye/group.rb', line 89

def restart
  chain_command :restart
end

#send_command(command, *args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/eye/group.rb', line 68

def send_command(command, *args)
  info "send_command: #{command}"

  case command
    when :delete
      delete *args
    when :break_chain 
      break_chain *args
    else 
      schedule command, *args, "#{command} by user"
  end
end

#signal(sig) ⇒ Object



106
107
108
# File 'lib/eye/group.rb', line 106

def signal(sig)
  async_schedule :signal, sig
end

#startObject



81
82
83
# File 'lib/eye/group.rb', line 81

def start
  chain_command :start
end

#status_data(debug = false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eye/group.rb', line 41

def status_data(debug = false)
  plist = @processes.map{|p| p.status_data(debug) }

  h = { name: name, type: :group, subtree: plist }

  h.merge!(debug: debug_data) if debug

  # show current chain
  if current_scheduled_command
    h.update(current_command: current_scheduled_command) 

    if (chain_commands = scheduler_actions_list) && chain_commands.present?
      h.update(chain_commands: chain_commands) 
    end

    if @chain_processes_current && @chain_processes_count
      h.update(chain_progress: [@chain_processes_current, @chain_processes_count]) 
    end
  end

  h
end

#stopObject



85
86
87
# File 'lib/eye/group.rb', line 85

def stop
  async_schedule :stop
end

#sub_object?(obj) ⇒ Boolean

Returns:



120
121
122
# File 'lib/eye/group.rb', line 120

def sub_object?(obj)
  @processes.include?(obj)
end

#unmonitorObject



102
103
104
# File 'lib/eye/group.rb', line 102

def unmonitor
  async_schedule :unmonitor
end

#update_config(cfg) ⇒ Object



27
28
29
30
# File 'lib/eye/group.rb', line 27

def update_config(cfg)
  @config = cfg
  @full_name = nil
end