Skip to content

Commit

Permalink
refactor: abstract core __call__ processing
Browse files Browse the repository at this point in the history
Makes the core of all run actions' __call__ a sequence of pre-process, job start, run and post-process.

Signed-off-by: Joe Shimkus <[email protected]>
  • Loading branch information
jshimkus-rh committed Oct 25, 2023
1 parent 7d35428 commit f21c224
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ansible_rulebook/action/run_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def __init__(self, metadata: Metadata, control: Control, **action_args):
self.name = self.action_args["name"]

async def __call__(self):
raise NotImplementedError
await self._pre_process()
await self._job_start_event()
await self._run()
await self._post_process()

async def _do_run(self) -> bool:
raise NotImplementedError
Expand All @@ -84,8 +87,6 @@ async def _run(self):
if not retry:
break

await self._post_process()

async def _pre_process(self) -> None:
pass

Expand Down Expand Up @@ -167,8 +168,7 @@ async def __call__(self):
self.job_args["extra_vars"] = self.helper.collect_extra_vars(
self.job_args.get("extra_vars", {})
)
await self._job_start_event()
await self._run()
await super().__call__()

async def _do_run(self) -> bool:
exception = False
Expand Down
6 changes: 2 additions & 4 deletions ansible_rulebook/action/run_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ async def __call__(self):
f"rule: {self.helper.metadata.rule}"
)
logger.debug("private data dir %s", self.private_data_dir)
await self._pre_process()
await self._job_start_event()
logger.info("Calling Ansible runner")
await self._run()
await super().__call__()
finally:
if os.path.exists(self.private_data_dir):
shutil.rmtree(self.private_data_dir)

async def _do_run(self) -> bool:
logger.info("Calling Ansible runner")
await Runner(
self.private_data_dir,
self.host_limit,
Expand Down

0 comments on commit f21c224

Please sign in to comment.