mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 11:41:08 -03:30
slightly refactor isolated event consumption
This commit is contained in:
@@ -187,7 +187,33 @@ class IsolatedManager(object):
|
|||||||
self.private_data_dir,
|
self.private_data_dir,
|
||||||
extravars=extravars)
|
extravars=extravars)
|
||||||
status, rc = runner_obj.status, runner_obj.rc
|
status, rc = runner_obj.status, runner_obj.rc
|
||||||
|
self.consume_events(dispatcher)
|
||||||
|
|
||||||
|
last_check = time.time()
|
||||||
|
|
||||||
|
if status == 'successful':
|
||||||
|
status_path = self.path_to('artifacts', self.ident, 'status')
|
||||||
|
rc_path = self.path_to('artifacts', self.ident, 'rc')
|
||||||
|
with open(status_path, 'r') as f:
|
||||||
|
status = f.readline()
|
||||||
|
with open(rc_path, 'r') as f:
|
||||||
|
rc = int(f.readline())
|
||||||
|
|
||||||
|
# consume events one last time just to be sure we didn't miss anything
|
||||||
|
# in the final sync
|
||||||
|
self.consume_events(dispatcher)
|
||||||
|
|
||||||
|
# emit an EOF event
|
||||||
|
event_data = {
|
||||||
|
'event': 'EOF',
|
||||||
|
'final_counter': len(self.handled_events)
|
||||||
|
}
|
||||||
|
event_data.setdefault(self.event_data_key, self.instance.id)
|
||||||
|
dispatcher.dispatch(event_data)
|
||||||
|
|
||||||
|
return status, rc
|
||||||
|
|
||||||
|
def consume_events(self, dispatcher):
|
||||||
# discover new events and ingest them
|
# discover new events and ingest them
|
||||||
events_path = self.path_to('artifacts', self.ident, 'job_events')
|
events_path = self.path_to('artifacts', self.ident, 'job_events')
|
||||||
|
|
||||||
@@ -221,25 +247,6 @@ class IsolatedManager(object):
|
|||||||
self.instance.artifacts = event_data['event_data']['artifact_data']
|
self.instance.artifacts = event_data['event_data']['artifact_data']
|
||||||
self.instance.save(update_fields=['artifacts'])
|
self.instance.save(update_fields=['artifacts'])
|
||||||
|
|
||||||
last_check = time.time()
|
|
||||||
|
|
||||||
if status == 'successful':
|
|
||||||
status_path = self.path_to('artifacts', self.ident, 'status')
|
|
||||||
rc_path = self.path_to('artifacts', self.ident, 'rc')
|
|
||||||
with open(status_path, 'r') as f:
|
|
||||||
status = f.readline()
|
|
||||||
with open(rc_path, 'r') as f:
|
|
||||||
rc = int(f.readline())
|
|
||||||
|
|
||||||
# emit an EOF event
|
|
||||||
event_data = {
|
|
||||||
'event': 'EOF',
|
|
||||||
'final_counter': len(self.handled_events)
|
|
||||||
}
|
|
||||||
event_data.setdefault(self.event_data_key, self.instance.id)
|
|
||||||
dispatcher.dispatch(event_data)
|
|
||||||
|
|
||||||
return status, rc
|
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
# If the job failed for any reason, make a last-ditch effort at cleanup
|
# If the job failed for any reason, make a last-ditch effort at cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user