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

Conversation

nkaretnikov
Copy link
Contributor

Fixes #560.

@netlify
Copy link

netlify bot commented Sep 14, 2023

Deploy Preview for kaleidoscopic-dango-0cf31d canceled.

Name Link
🔨 Latest commit 4223ac1
🔍 Latest deploy log https://app.netlify.com/sites/kaleidoscopic-dango-0cf31d/deploys/6502e2f2bc2dd10008e761a0

@@ -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

build.deleted_on = datetime.datetime.utcnow()
build.size = 0

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


# 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)

@nkaretnikov
Copy link
Contributor Author

To test that this works:

  • Remove all DB state files from before if you have any
  • Log in
  • Create this env via http://localhost:5000/admin/create/:
channels:
- conda-forge
dependencies:
- rust>=1.71.1
- binutils-meta>=1.0.4
- gcc>=12.2.0
- llvm-meta>=13.0.1
- cudatoolkit-dev>=11.4.0
description: slow env
name: slow
prefix: null
variables: null
  • Go to http://localhost:5000/admin/environment/default/slow/ and wait for the build to complete (takes around 5 mins)
  • Once complete, see if the size on the same page has updated. For me, it shows default/slow 7.3 GiB
  • Delete Build 1 (this build) by clicking on the Trash Bin icon on the same page
  • Web UI should immediately update to default/slow 0 Bytes
  • Click on the Rebuild icon on the same page to build this env again
  • Wait 5 mins or so for Build 2 to complete
  • Once done, the Web UI should show default/slow 7.3 GiB again.

@nkaretnikov nkaretnikov marked this pull request as ready for review September 14, 2023 11:11
@pierrotsmnrd pierrotsmnrd self-requested a review September 14, 2023 14:05
@pierrotsmnrd
Copy link
Contributor

Tested locally, and code reviewed : It works, with PR 574 being merged. So merge 574 before merging this one.

@pierrotsmnrd pierrotsmnrd merged commit 469afda into conda-incubator:main Sep 14, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

[BUG] - Delete environment does not change storage size
2 participants