Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build metadata on deletion, fix misc bugs #572

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions conda-store-server/conda_store_server/worker/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import shutil
import os

Expand Down Expand Up @@ -231,7 +232,7 @@ def delete_build_artifact(db: Session, conda_store, build_artifact):
# ignore key
conda_prefix = build_artifact.build.build_path(conda_store)
# be REALLY sure this is a directory within store directory
if conda_prefix.startswith(conda_store.store_directory) and os.path.isdir(
if str(conda_prefix).startswith(conda_store.store_directory) and os.path.isdir(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix: PosixPath object (conda_prefix) has no attribute startswith, so need to convert to str first

conda_prefix
):
shutil.rmtree(conda_prefix)
Expand All @@ -254,14 +255,20 @@ def task_delete_build(self, build_id):

build = api.get_build(db, build_id)

# Deletes build artifacts for this build
conda_store.log.info(f"deleting artifacts for build={build.id}")
for build_artifact in api.list_build_artifacts(
db,
build_id=build_id,
excluded_artifact_types=settings.build_artifacts_kept_on_deletion,
).all():
delete_build_artifact(db, conda_store, build_artifact)
conda_store.db.commit()

# Updates build size and marks build as deleted
build.deleted_on = datetime.datetime.utcnow()
build.size = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata fix: size value of the current build is shown in the web UI as size. Need to update that when deleting artifacts here.

How it works in more detail:

{% for environment in environments %}
<div class="card my-2">
    <div class="card-body">
        <h5 class="card-title">
            <a href="{{ url_for('ui_get_environment', namespace=environment.namespace.name, environment_name=environment.name) }}">{{ environment.namespace.name }} / <span class="badge badge-info">{{ environment.name }}</span></a>
            <span class="badge badge-light">{{ (environment.current_build.size or 0) | filesizeformat(true) }}</span>
        </h5>

=>

 document.querySelectorAll('button[data-action="delete"]').forEach(item => {
     item.addEventListener('click', (event) => deleteBuild(event));
 })

=>

 async function deleteBuild(event) {
...
     let url = `{{ url_for('api_list_builds') }}${ buildId }/`;
     let response = await fetch(url, { method: 'DELETE' });
...

=>

@router_api.delete(
    "/build/{build_id}/",
    response_model=schema.APIAckResponse,
)
async def api_delete_build(
...
        conda_store.delete_build(db, build_id)

=>

     def delete_build(self, db: Session, build_id: int):
...
        tasks.task_delete_build.si(build.id).apply_async()

=>

task_delete_build (this function)


db.commit()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix: CondaStore object has no attribute db, need to just use db for this



@shared_task(base=WorkerTask, name="task_delete_environment", bind=True)
Expand Down
Loading