Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix receptor work unit release after completion #15679

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions awx/main/tasks/receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,40 @@
res = self._run_internal(receptor_ctl)
return res
finally:
# Make sure to always release the work unit if we established it
if self.unit_id is not None and settings.RECEPTOR_RELEASE_WORK:
if settings.RECPETOR_KEEP_WORK_ON_ERROR and getattr(res, 'status', 'error') == 'error':
try:
receptor_ctl.simple_command(f"work release {self.unit_id}")
except Exception:
logger.exception(f"Error releasing work unit {self.unit_id}.")
status = getattr(res, 'status', 'error')
self._receptor_release_work(receptor_ctl, status)

Check warning on line 407 in awx/main/tasks/receptor.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/receptor.py#L406-L407

Added lines #L406 - L407 were not covered by tests

def _receptor_release_work(self, receptor_ctl: ReceptorControl, status: str) -> None:
TheRealHaoLiu marked this conversation as resolved.
Show resolved Hide resolved
"""
Releases the work unit from Receptor if certain conditions are met.
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

Check warning on line 425 in awx/main/tasks/receptor.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/receptor.py#L424-L425

Added lines #L424 - L425 were not covered by tests

if settings.RECEPTOR_RELEASE_WORK is False:
logger.debug(f"RECEPTOR_RELEASE_WORK is False, not releasing work unit {self.unit_id}.")
return

Check warning on line 429 in awx/main/tasks/receptor.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/receptor.py#L428-L429

Added lines #L428 - L429 were not covered by tests

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

Check warning on line 433 in awx/main/tasks/receptor.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/receptor.py#L432-L433

Added lines #L432 - L433 were not covered by tests

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}.")

Check warning on line 439 in awx/main/tasks/receptor.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/receptor.py#L435-L439

Added lines #L435 - L439 were not covered by tests

def _run_internal(self, receptor_ctl):
# Create a socketpair. Where the left side will be used for writing our payload
Expand Down
Loading