Class: Eye::Group

Inherits:
Object show all
Includes:
Celluloid, Chain, 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

Instance Method Summary collapse

Methods included from Process::Scheduler

included, #schedule, #schedule_history, #schedule_in, #scheduled_action, #scheduler_actions_list, #scheduler_clear_pending_list, #scheduler_freeze, #scheduler_freeze?, #scheduler_unfreeze

Constructor Details

#initialize(name, config) ⇒ Group

Returns a new instance of Group.


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

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


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

def config
  @config
end

#hiddenObject (readonly)

Returns the value of attribute hidden


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

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

#processesObject (readonly)

Returns the value of attribute processes


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

def processes
  @processes
end

Instance Method Details

#add_process(process) ⇒ Object


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

def add_process(process)
  @processes << process
end

#app_nameObject


25
26
27
# File 'lib/eye/group.rb', line 25

def app_name
  @config[:application]
end

#break_chainObject


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

def break_chain
  info 'break chain'
  scheduler_clear_pending_list
  @chain_breaker = true
end

#clearObject


130
131
132
# File 'lib/eye/group.rb', line 130

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

#debug_dataObject


70
71
72
# File 'lib/eye/group.rb', line 70

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

#deleteObject


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

def delete
  async_schedule :delete
  terminate
end

#freezeObject


126
127
128
# File 'lib/eye/group.rb', line 126

def freeze
  async_schedule :freeze
end

#full_nameObject


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

def full_name
  @full_name ||= "#{app_name}:#{@name}"
end

#logger_tagObject


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

def logger_tag
  full_name
end

#monitorObject


104
105
106
# File 'lib/eye/group.rb', line 104

def monitor
  chain_command :monitor
end

#resort_processesObject

sort processes in name order


43
44
45
# File 'lib/eye/group.rb', line 43

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

#restartObject


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

def restart
  chain_command :restart
end

#send_command(command, *args) ⇒ Object


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/eye/group.rb', line 74

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, Eye::Reason::User.new(command)
  end
end

#signal(sig) ⇒ Object


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

def signal(sig)
  async_schedule :signal, sig
end

#startObject


87
88
89
# File 'lib/eye/group.rb', line 87

def start
  chain_command :start
end

#status_data(debug = false) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/eye/group.rb', line 47

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


91
92
93
# File 'lib/eye/group.rb', line 91

def stop
  async_schedule :stop
end

#sub_object?(obj) ⇒ Boolean

Returns:

  • (Boolean)

134
135
136
# File 'lib/eye/group.rb', line 134

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

#unmonitorObject


108
109
110
# File 'lib/eye/group.rb', line 108

def unmonitor
  async_schedule :unmonitor
end

#update_config(cfg) ⇒ Object


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

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

#user_command(cmd) ⇒ Object


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

def user_command(cmd)
  async_schedule :user_command, cmd
end