mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 04:15:02 -02:30
Fix bug introduced by https://github.com/ansible/awx/pull/15392 that cause workunit to NOT be auto released after job completes
This commit is contained in:
@@ -403,13 +403,40 @@ class AWXReceptorJob:
|
|||||||
res = self._run_internal(receptor_ctl)
|
res = self._run_internal(receptor_ctl)
|
||||||
return res
|
return res
|
||||||
finally:
|
finally:
|
||||||
# Make sure to always release the work unit if we established it
|
status = getattr(res, 'status', 'error')
|
||||||
if self.unit_id is not None and settings.RECEPTOR_RELEASE_WORK:
|
self._receptor_release_work(receptor_ctl, status)
|
||||||
if settings.RECPETOR_KEEP_WORK_ON_ERROR and getattr(res, 'status', 'error') == 'error':
|
|
||||||
try:
|
def _receptor_release_work(self, receptor_ctl: ReceptorControl, status: str) -> None:
|
||||||
receptor_ctl.simple_command(f"work release {self.unit_id}")
|
"""
|
||||||
except Exception:
|
Releases the work unit from Receptor if certain conditions are met.
|
||||||
logger.exception(f"Error releasing work unit {self.unit_id}.")
|
This method checks several conditions before attempting to release the work unit:
|
||||||
|
- If `self.unit_id` is `None`, the method returns immediately.
|
||||||
|
- If the `RECEPTOR_RELEASE_WORK` setting is `False`, the method returns immediately.
|
||||||
|
- If the `RECEPTOR_KEEP_WORK_ON_ERROR` setting is `True` and the status is 'error', the method returns immediately.
|
||||||
|
If none of the above conditions are met, the method attempts to release the work unit using the Receptor control command.
|
||||||
|
If an exception occurs during the release process, it logs an error message.
|
||||||
|
Args:
|
||||||
|
receptor_ctl (ReceptorControl): The Receptor control object used to issue commands.
|
||||||
|
status (str): The status of the work unit, which may affect whether it is released.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.unit_id is None:
|
||||||
|
logger.debug("No work unit ID to release.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if settings.RECEPTOR_RELEASE_WORK is False:
|
||||||
|
logger.debug(f"RECEPTOR_RELEASE_WORK is False, not releasing work unit {self.unit_id}.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if settings.RECEPTOR_KEEP_WORK_ON_ERROR and status == 'error':
|
||||||
|
logger.debug(f"RECEPTOR_KEEP_WORK_ON_ERROR is True and status is 'error', not releasing work unit {self.unit_id}.")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.debug(f"Released work unit {self.unit_id}.")
|
||||||
|
receptor_ctl.simple_command(f"work release {self.unit_id}")
|
||||||
|
except Exception:
|
||||||
|
logger.exception(f"Error releasing work unit {self.unit_id}.")
|
||||||
|
|
||||||
def _run_internal(self, receptor_ctl):
|
def _run_internal(self, receptor_ctl):
|
||||||
# Create a socketpair. Where the left side will be used for writing our payload
|
# Create a socketpair. Where the left side will be used for writing our payload
|
||||||
|
|||||||
Reference in New Issue
Block a user