Skip to content

Commit

Permalink
Manual mechanism for deleting builds (#94)
Browse files Browse the repository at this point in the history
* Minimal implementation of deletion of conda environments

* Black formatting
  • Loading branch information
costrouc authored Jul 25, 2021
1 parent d1bf811 commit 4ee8463
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def list_build_artifacts(db, limit: int = 25, build_id: int = None, key: str = N
if key:
filters.append(orm.BuildArtifact.key == key)

return db.query(orm.BuildArtifact).filter(**filters).limit(limit).all()
return db.query(orm.BuildArtifact).filter(*filters).limit(limit).all()


def get_build_artifact(db, build_id, key):
Expand Down
12 changes: 12 additions & 0 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,15 @@ def update_environment_build(self, name, build_id):
from conda_store_server.worker import tasks

tasks.task_update_environment_build.si(environment.id, build.id).apply_async()

def delete_build(self, build_id):
build = api.get_build(self.db, build_id)
if build.status not in [orm.BuildStatus.FAILED, orm.BuildStatus.COMPLETED]:
raise ValueError("cannot delete build since not finished building")

self.celery_app

# must import tasks after a celery app has been initialized
from conda_store_server.worker import tasks

tasks.task_delete_build.si(build.id).apply_async()
11 changes: 11 additions & 0 deletions conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ def api_put_build(build_id):
return jsonify({"status": "error", "error": "build id does not exist"}), 400


@app_api.route("/api/v1/build/<build_id>/", methods=["DELETE"])
def api_delete_build(build_id):
conda_store = get_conda_store()
build = api.get_build(conda_store.db, build_id)
if build is not None:
conda_store.delete_build(build_id)
return jsonify({"status": "ok"})
else:
return jsonify({"status": "error", "error": "build id does not exist"}), 400


@app_api.route("/api/v1/build/<build_id>/logs/", methods=["GET"])
def api_get_build_logs(build_id):
conda_store = get_conda_store()
Expand Down
20 changes: 20 additions & 0 deletions conda-store-server/conda_store_server/worker/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import shutil

from celery.decorators import task
import yaml

Expand Down Expand Up @@ -83,3 +85,21 @@ def task_update_environment_build(environment_id, build_id):
environment.build_id = build.id
environment.specification_id = build.specification.id
conda_store.db.commit()


@task(name="task_delete_build")
def task_delete_build(build_id):
conda_store = create_worker().conda_store
build = api.get_build(conda_store.db, build_id)

conda_prefix = build.build_path(conda_store.store_directory)

shutil.rmtree(conda_prefix)

for build_artifact in api.list_build_artifacts(
conda_store.db, limit=None, build_id=build_id
):
conda_store.storage.delete(conda_store.db, build_id, build_artifact.key)

conda_store.db.delete(build)
conda_store.db.commit()

0 comments on commit 4ee8463

Please sign in to comment.