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 c5c7af0d8..a377ee6eb 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):