diff --git a/conda-store-server/conda_store_server/_internal/schema.py b/conda-store-server/conda_store_server/_internal/schema.py index a58344073..78e750886 100644 --- a/conda-store-server/conda_store_server/_internal/schema.py +++ b/conda-store-server/conda_store_server/_internal/schema.py @@ -113,6 +113,8 @@ class BuildStatus(enum.Enum): COMPLETED = "COMPLETED" FAILED = "FAILED" CANCELED = "CANCELED" + DELETED = "DELETED" + ARCHIVED = "ARCHIVED" class BuildArtifact(BaseModel): diff --git a/conda-store-server/conda_store_server/_internal/worker/tasks.py b/conda-store-server/conda_store_server/_internal/worker/tasks.py index b0cddd1bc..4959a0cf1 100644 --- a/conda-store-server/conda_store_server/_internal/worker/tasks.py +++ b/conda-store-server/conda_store_server/_internal/worker/tasks.py @@ -298,6 +298,7 @@ def task_delete_build(self, build_id): # Updates build size and marks build as deleted build.deleted_on = datetime.datetime.utcnow() + build.status = schema.BuildStatus.DELETED build.size = 0 db.commit() diff --git a/conda-store-server/conda_store_server/conda_store.py b/conda-store-server/conda_store_server/conda_store.py index cccb9a16c..ebba73347 100644 --- a/conda-store-server/conda_store_server/conda_store.py +++ b/conda-store-server/conda_store_server/conda_store.py @@ -542,6 +542,7 @@ def delete_build(self, db: Session, build_id: int): raise CondaStoreError("cannot delete build since not finished building") build.deleted_on = datetime.datetime.utcnow() + build.status = schema.BuildStatus.DELETED db.commit() self.celery_app diff --git a/conda-store-server/tests/test_conda_store.py b/conda-store-server/tests/test_conda_store.py index 4386abbd6..573266068 100644 --- a/conda-store-server/tests/test_conda_store.py +++ b/conda-store-server/tests/test_conda_store.py @@ -189,3 +189,19 @@ def test_conda_store_get_lock_plugin_does_not_exist(conda_store): conda_store.config.lock_backend = lock_plugin_setting with pytest.raises(CondaStorePluginNotFoundError): conda_store.lock_plugin() + + +def test_conda_store_delete_build(seed_conda_store, conda_store): + """Ensure conda store will delete a build and update all appropriate metadata""" + db = seed_conda_store + + # build 4 is completed, we'll use that test test deletion + build = api.get_build(db, build_id=4) + assert build.deleted_on is None + assert build.status == schema.BuildStatus.COMPLETED + + conda_store.delete_build(db, 4) + + build = api.get_build(db, build_id=4) + assert build.deleted_on is not None + assert build.status == schema.BuildStatus.DELETED