-
Notifications
You must be signed in to change notification settings - Fork 52
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import datetime | ||
import shutil | ||
import os | ||
|
||
|
@@ -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( | ||
conda_prefix | ||
): | ||
shutil.rmtree(conda_prefix) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug fix: |
||
|
||
|
||
@shared_task(base=WorkerTask, name="task_delete_environment", bind=True) | ||
|
There was a problem hiding this comment.
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 attributestartswith
, so need to convert tostr
first