From c92c20189150b3d514a1af0e3cbd47dfffa130fb Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Fri, 28 May 2021 14:58:34 +0200 Subject: [PATCH 1/2] + `WorkContext.terminate()` + `ctx.terminate()` as a default operation in the default `Service.shutdown` handler --- tests/executor/test_ctx.py | 10 ++++++++++ yapapi/executor/ctx.py | 11 +++++++++++ yapapi/executor/services.py | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/executor/test_ctx.py b/tests/executor/test_ctx.py index ef2d08a08..678477b86 100644 --- a/tests/executor/test_ctx.py +++ b/tests/executor/test_ctx.py @@ -126,3 +126,13 @@ async def test_download_json(self): await steps.post() self._assert_src_path(steps, src_path) assert self._on_download_executed + + def test_terminate(self): + ctx = self._get_work_context(None) + ctx.terminate() + steps = ctx.commit() + + c = CommandContainer() + steps.register(c) + + assert c.commands() == [{'terminate': {}}] diff --git a/yapapi/executor/ctx.py b/yapapi/executor/ctx.py index c4fbc15a1..e7e36fc2e 100644 --- a/yapapi/executor/ctx.py +++ b/yapapi/executor/ctx.py @@ -61,6 +61,11 @@ def register(self, commands: CommandContainer): commands.start() +class _Terminate(Work): + def register(self, commands: CommandContainer): + commands.terminate() + + class _SendWork(Work, abc.ABC): def __init__(self, storage: StorageProvider, dst_path: str): self._storage = storage @@ -306,13 +311,19 @@ def begin(self): pass def deploy(self): + """Schedule a Deploy command.""" self._implicit_init = False self._pending_steps.append(_Deploy()) def start(self): + """Schedule a Start command.""" self._implicit_init = False self._pending_steps.append(_Start()) + def terminate(self): + """Schedule a Terminate command.""" + self._pending_steps.append(_Terminate()) + def send_json(self, json_path: str, data: dict): """Schedule sending JSON data to the provider. diff --git a/yapapi/executor/services.py b/yapapi/executor/services.py index f25461583..73df279a8 100644 --- a/yapapi/executor/services.py +++ b/yapapi/executor/services.py @@ -146,7 +146,8 @@ async def run(self): yield async def shutdown(self): - yield + self._ctx.terminate() + yield self._ctx.commit() @property def is_available(self): From 6a5f4224207e8a4ef71794fe5da52e1101c636b3 Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Fri, 28 May 2021 15:14:01 +0200 Subject: [PATCH 2/2] black ... --- tests/executor/test_ctx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/executor/test_ctx.py b/tests/executor/test_ctx.py index 678477b86..bbc9ba509 100644 --- a/tests/executor/test_ctx.py +++ b/tests/executor/test_ctx.py @@ -135,4 +135,4 @@ def test_terminate(self): c = CommandContainer() steps.register(c) - assert c.commands() == [{'terminate': {}}] + assert c.commands() == [{"terminate": {}}]