89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/wakame/master_managers/action_manager.rb', line 89
def run_action(action)
raise ArgumentError unless action.is_a?(Action)
job_context = @active_jobs[action.job_id]
raise "The job session is killed.: job_id=#{action.job_id}" if job_context.nil?
EM.next_tick {
begin
if job_context[:start_at].nil?
job_context[:start_at] = Time.new
ED.fire_event(Event::JobStart.new(action.job_id))
end
EM.defer proc {
res = nil
begin
action.bind_thread(Thread.current)
action.status = :running
Wakame.log.debug("Start action : #{action.class.to_s} #{action.parent_action.nil? ? '' : ('sub-action of ' + action.parent_action.class.to_s)}")
ED.fire_event(Event::ActionStart.new(action))
begin
action.run
action.completion_status = :succeeded
Wakame.log.debug("Complete action : #{action.class.to_s}")
ED.fire_event(Event::ActionComplete.new(action))
end
rescue CancelBroadcast => e
Wakame.log.info("Received cancel signal: #{e}")
action.completion_status = :canceled
begin
action.on_canceled
rescue => e
Wakame.log.error(e)
end
ED.fire_event(Event::ActionFailed.new(action, e))
res = e
rescue => e
Wakame.log.error("Failed action : #{action.class.to_s} due to #{e}")
Wakame.log.error(e)
action.completion_status = :failed
begin
action.on_failed
rescue => e
Wakame.log.error(e)
end
ED.fire_event(Event::ActionFailed.new(action, e))
unless action.parent_action.nil?
action.parent_action.notify(e)
end
if action === job_context[:root_action]
Wakame.log.warn("The escalated exception (#{e.class}) has reached to the root action (#{action.class}). Forcing to cancel the current job #{job_context[:job_id]}")
cancel_action(job_context[:job_id]) end
res = e
ensure
action.status = :complete
action.bind_thread(nil)
end
StatusDB.pass {
process_job_complete(action, res)
}
}
rescue => e
Wakame.log.error(e)
end
}
end
|