Skip to content

Commit

Permalink
update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ammar257ammar committed Jan 17, 2025
1 parent 68a5d34 commit ea438ff
Showing 1 changed file with 65 additions and 68 deletions.
133 changes: 65 additions & 68 deletions app/grandchallenge/components/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ def update_container_image_shim(
@acks_late_2xlarge_task
def remove_inactive_container_images():
"""Removes inactive container images from the registry"""

from grandchallenge.algorithms.models import AlgorithmImage, Job
from grandchallenge.evaluation.models import Evaluation, Method
from grandchallenge.workstations.models import Session, WorkstationImage

for app_label, model_name, related_name in (
("algorithms", "algorithm", "algorithm_container_images"),
("evaluation", "phase", "method_set"),
Expand All @@ -213,69 +208,6 @@ def remove_inactive_container_images():
.exclude(pk=latest.pk)
.filter(is_in_registry=True)
):

instance = image
instance_in_use = False

if isinstance(instance, Method):
instance_in_use = (
Evaluation.objects.filter(
method=instance,
)
.exclude(
status__in=[
Evaluation.SUCCESS,
Evaluation.FAILURE,
Evaluation.CANCELLED,
]
)
.exists()
)

elif isinstance(instance, AlgorithmImage):
instance_in_use = (
Evaluation.objects.filter(
submission__algorithm_image=instance,
)
.exclude(
status__in=[
Evaluation.SUCCESS,
Evaluation.FAILURE,
Evaluation.CANCELLED,
]
)
.exists()
or Job.objects.filter(
algorithm_image=instance,
)
.exclude(
status__in=[
Job.SUCCESS,
Job.FAILURE,
Job.CANCELLED,
]
)
.exists()
)

elif isinstance(instance, WorkstationImage):
instance_in_use = (
Session.objects.filter(
workstation_image=instance,
)
.exclude(
status__in=[
Session.RUNNING,
Session.FAILED,
Session.STOPPED,
]
)
.exists()
)

if instance_in_use:
continue

on_commit(
remove_container_image_from_registry.signature(
kwargs={
Expand All @@ -295,6 +227,71 @@ def remove_container_image_from_registry(
model = apps.get_model(app_label=app_label, model_name=model_name)
instance = model.objects.get(pk=pk)

from grandchallenge.algorithms.models import AlgorithmImage, Job
from grandchallenge.evaluation.models import Evaluation, Method
from grandchallenge.workstations.models import Session, WorkstationImage

instance_in_use = False

if isinstance(instance, Method):
instance_in_use = (
Evaluation.objects.filter(
method=instance,
)
.exclude(
status__in=[
Evaluation.SUCCESS,
Evaluation.FAILURE,
Evaluation.CANCELLED,
]
)
.exists()
)

elif isinstance(instance, AlgorithmImage):
instance_in_use = (
Evaluation.objects.filter(
submission__algorithm_image=instance,
)
.exclude(
status__in=[
Evaluation.SUCCESS,
Evaluation.FAILURE,
Evaluation.CANCELLED,
]
)
.exists()
or Job.objects.filter(
algorithm_image=instance,
)
.exclude(
status__in=[
Job.SUCCESS,
Job.FAILURE,
Job.CANCELLED,
]
)
.exists()
)

elif isinstance(instance, WorkstationImage):
instance_in_use = (
Session.objects.filter(
workstation_image=instance,
)
.exclude(
status__in=[
Session.RUNNING,
Session.FAILED,
Session.STOPPED,
]
)
.exists()
)

if instance_in_use:
return

if instance.latest_shimmed_version:
remove_tag_from_registry(repo_tag=instance.shimmed_repo_tag)
instance.latest_shimmed_version = ""
Expand Down

0 comments on commit ea438ff

Please sign in to comment.