Skip to content

Commit

Permalink
fix: pass the controller job id to server via messages (#698)
Browse files Browse the repository at this point in the history
The JOB URL is going to be built on the server side since its difficult
for the ansible-rulebook to convert an API end point to a URL. If the
server has the controller_job_id and and the action type the server can
build the URL.


https://issues.redhat.com/browse/AAP-25604
  • Loading branch information
mkanoor authored Jun 21, 2024
1 parent c8aa69c commit f84eace
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed
### Added
- Support for switching slugs to connect to controller via gateway
- Support passing in controller job id to server so it can build Job URL
### Fixed
- Fix log level for websocket

Expand Down
3 changes: 2 additions & 1 deletion ansible_rulebook/action/run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ async def _post_process(self) -> None:
"run_at": self.controller_job["created"],
"url": self._controller_job_url(),
"matching_events": self.helper.get_events(),
"controller_job_id": self.controller_job.get("id", ""),
}
if "error" in self.controller_job:
a_log["message"] = self.controller_job["error"]
a_log["reason"] = {"error": self.controller_job["error"]}
else:
logger.info(f"job results url: {a_log['url']}")
logger.info(f"job id: {a_log['job_id']}")
logger.info(f"controller job id: {a_log['controller_job_id']}")

await self.helper.send_status(a_log)
set_facts = self.action_args.get("set_facts", False)
Expand Down
3 changes: 2 additions & 1 deletion ansible_rulebook/action/run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ async def _post_process(self) -> None:
"run_at": self.controller_job["created"],
"url": self._controller_job_url(),
"matching_events": self.helper.get_events(),
"controller_job_id": self.controller_job.get("id", ""),
}
if "error" in self.controller_job:
a_log["message"] = self.controller_job["error"]
a_log["reason"] = {"error": self.controller_job["error"]}
else:
logger.info(f"job results url: {a_log['url']}")
logger.info(f"job id: {a_log['job_id']}")
logger.info(f"controller job id: {a_log['controller_job_id']}")

await self.helper.send_status(a_log)
set_facts = self.action_args.get("set_facts", False)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/action/test_run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def _validate(queue, success, reason=None):
"url",
"organization",
"job_id",
"controller_job_id",
}

if not success:
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/action/test_run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def _validate(queue, success, reason=None):
"url",
"organization",
"job_id",
"controller_job_id",
}

if not success:
Expand Down Expand Up @@ -233,8 +234,8 @@ async def test_run_workflow_template_retries():


URL_PARAMETERS = [
(None,),
(10,),
None,
10,
]


Expand Down

0 comments on commit f84eace

Please sign in to comment.