From c6be12e31e306345d24033774f0d0c6cdb9d9587 Mon Sep 17 00:00:00 2001 From: Charlton Austin Date: Mon, 5 Dec 2016 14:56:18 -0500 Subject: [PATCH] Adding in a cancel method to the build component so we can properly clean up the job task. --- buildman/component/buildcomponent.py | 6 ++++++ buildman/manager/ephemeral.py | 4 +++- data/database.py | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/buildman/component/buildcomponent.py b/buildman/component/buildcomponent.py index 47afe798d..e7730cd81 100644 --- a/buildman/component/buildcomponent.py +++ b/buildman/component/buildcomponent.py @@ -490,3 +490,9 @@ class BuildComponent(BaseComponent): # Remove the job reference. self._current_job = None + + @trollius.coroutine + def cancel_build(self): + self.parent_manager.build_component_disposed(self, True) + self._current_job = None + yield From(self._set_status(ComponentStatus.RUNNING)) diff --git a/buildman/manager/ephemeral.py b/buildman/manager/ephemeral.py index 2270f5fd5..f026b61d9 100644 --- a/buildman/manager/ephemeral.py +++ b/buildman/manager/ephemeral.py @@ -727,10 +727,12 @@ class EphemeralBuilderManager(BaseManager): raise Return(False) got_lock = yield From(self._take_etcd_atomic_lock('job-cancelled', build_uuid, build_info.execution_id)) if got_lock: + yield From(self.kill_builder_executor(build_uuid)) yield From(self.delete_etcd_key(self._etcd_realm_key(build_info.component.builder_realm))) yield From(self.delete_etcd_key(self._etcd_metric_key(build_info.component.builder_realm))) yield From(self.delete_etcd_key(os.path.join(self._etcd_job_prefix, build_uuid))) - yield From(self.kill_builder_executor(build_uuid)) + # This is outside the lock so we can un-register the component wherever it is registered to. + yield From(build_info.component.cancel_build()) @coroutine def delete_etcd_key(self, etcd_key): diff --git a/data/database.py b/data/database.py index afc1573b4..b94f38391 100644 --- a/data/database.py +++ b/data/database.py @@ -747,7 +747,8 @@ class BUILD_PHASE(object): def is_terminal_phase(cls, phase): return (phase == cls.COMPLETE or phase == cls.ERROR or - phase == cls.INTERNAL_ERROR) + phase == cls.INTERNAL_ERROR or + phase == cls.CANCELLED) class QueueItem(BaseModel):