Move error handling into try/catch block

This commit is contained in:
Bianca Henderson 2021-10-14 14:52:38 -04:00 committed by Shane McDonald
parent 7b35902d33
commit f72292cce2
No known key found for this signature in database
GPG Key ID: 6F374AF6E9EB9374

View File

@ -3122,9 +3122,14 @@ class AWXReceptorJob:
resultsock.shutdown(socket.SHUT_RDWR)
resultfile.close()
elif res.status == 'error':
unit_status = receptor_ctl.simple_command(f'work status {self.unit_id}')
detail = unit_status['Detail']
state_name = unit_status['StateName']
try:
unit_status = receptor_ctl.simple_command(f'work status {self.unit_id}')
detail = unit_status.get('Detail', None)
state_name = unit_status.get('StateName', None)
except RuntimeError as e:
detail = ''
state_name = ''
logger.warn(e)
if 'exceeded quota' in detail:
logger.warn(detail)