Module: Mamiya::Master::AgentMonitorHandlers

Included in:
AgentMonitor
Defined in:
lib/mamiya/master/agent_monitor_handlers.rb

Overview

XXX: TODO:

Instance Method Summary collapse

Instance Method Details

#pkg__remove(status, payload, event) ⇒ Object



85
86
87
88
89
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 85

def pkg__remove(status, payload, event)
  status['packages'] ||= {}
  packages = status['packages'][payload['application']]
  packages.delete(payload['package']) if packages
end

#prerelease__remove(status, payload, event) ⇒ Object



91
92
93
94
95
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 91

def prerelease__remove(status, payload, event)
  status['prereleases'] ||= {}
  prereleases = status['prereleases'][payload['app']]
  prereleases.delete(payload['pkg']) if prereleases
end

#release__remove(status, payload, event) ⇒ Object



97
98
99
100
101
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 97

def release__remove(status, payload, event)
  status['releases'] ||= {}
  releases = status['releases'][payload['app']]
  releases.delete(payload['pkg']) if releases
end

#task___fetch__finish(status, task) ⇒ Object

XXX: move task finish handlers into tasks/



57
58
59
60
61
62
63
64
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 57

def task___fetch__finish(status, task)
  status['packages'] ||= {}
  status['packages'][task['app']] ||= []

  unless status['packages'][task['app']].include?(task['pkg'])
    status['packages'][task['app']] << task['pkg']
  end
end

#task___prepare__finish(status, task) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 66

def task___prepare__finish(status, task)
  status['prereleases'] ||= {}
  status['prereleases'][task['app']] ||= []

  unless status['prereleases'][task['app']].include?(task['pkg'])
    status['prereleases'][task['app']] << task['pkg']
  end
end

#task___switch__finish(status, task) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 75

def task___switch__finish(status, task)
  status['currents'] ||= {}
  status['currents'][task['app']] = task['pkg']

  status['releases'] ||= {}
  status['releases'][task['app']] ||= []
  status['releases'][task['app']].push task['pkg']
  status['releases'][task['app']].uniq!
end

#task__error(status, payload, event) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 42

def task__error(status, payload, event)
  task = payload['task']
  logger.error "#{status['name']} has failed task #{task['task'].inspect}: #{payload['error']}"

  task__finalize(status, payload, event)

  method_name = "task___#{task['task']}__error"
  if self.respond_to?(method_name)
    __send__ method_name, status, task, error
  end
end

#task__finalize(status, payload, event) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 17

def task__finalize(status, payload, event)
  task = payload['task']

  status['queues'] ||= {}
  status['queues'][task['task']] ||= {'queue' => [], 'working' => nil}

  s = status['queues'][task['task']]
  if s['working'] == task
    s['working'] = nil
  end
  status['queues'][task['task']]['queue'].delete task
end

#task__finish(status, payload, event) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 30

def task__finish(status, payload, event)
  task = payload['task']
  logger.info "#{status['name']} has finished task #{task['task'].inspect}"

  task__finalize(status, payload, event)

  method_name = "task___#{task['task']}__finish"
  if self.respond_to?(method_name)
    __send__ method_name, status, task
  end
end

#task__start(status, payload, event) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/mamiya/master/agent_monitor_handlers.rb', line 7

def task__start(status, payload, event)
  task = payload['task']

  status['queues'] ||= {}
  status['queues'][task['task']] ||= {'queue' => [], 'working' => nil}

  status['queues'][task['task']]['working'] = task
  status['queues'][task['task']]['queue'].delete task
end