Skip to content

Commit

Permalink
Add task to archive builds
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Jan 16, 2025
1 parent 89d1d42 commit dbfa438
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ async def api_archive_build(
except CondaStoreError as e:
raise HTTPException(status_code=400, detail=e.message)

return {"status": schema.APIStatus.OK}
return {"status": schema.APIStatus.OK}


@router_api.get(
Expand Down
24 changes: 24 additions & 0 deletions conda-store-server/conda_store_server/_internal/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ def task_delete_build(self, build_id):
db.commit()


@shared_task(base=WorkerTask, name="task_archive_build", bind=True)
def task_archive_build(self, build_id):
conda_store = self.worker.conda_store
with conda_store.session_factory() as db:
build = api.get_build(db, build_id)

archive_save_artifacts = [schema.BuildArtifactType.LOCKFILE, schema.BuildArtifactType.LOGS]
# Deletes build artifacts for this build
conda_store.log.info(f"archiving build={build.id}")
for build_artifact in api.list_build_artifacts(
db,
build_id=build_id,
excluded_artifact_types=archive_save_artifacts,
).all():
conda_store.log.info(f"archiving build={build.id} - deleting artifact {build_artifact.artifact_type.value}")
delete_build_artifact(db, conda_store, build_artifact)

# Updates build size and marks build as deleted
build.archived_on = datetime.datetime.utcnow()
build.status = schema.BuildStatus.ARCHIVED
build.size = 0
db.commit()


@shared_task(base=WorkerTask, name="task_delete_environment", bind=True)
def task_delete_environment(self, environment_id):
conda_store = self.worker.conda_store
Expand Down
14 changes: 8 additions & 6 deletions conda-store-server/conda_store_server/conda_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,12 @@ def archive_build(self, db: Session, build_id: int):
action=auth_schema.Permissions.BUILD_ARCHIVE,
)

if build.status not in [
schema.BuildStatus.FAILED,
schema.BuildStatus.COMPLETED,
]:
raise CondaStoreError("cannot archive build since not finished building")
if build.status != schema.BuildStatus.COMPLETED:
raise CondaStoreError(f"cannot archive build that is in the {build.status.value} state")

self.celery_app

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

# TODO: archive build
tasks.task_archive_build.si(build.id).apply_async()

0 comments on commit dbfa438

Please sign in to comment.