Skip to content

Commit

Permalink
feat: delete jobs that are more than a year older than the active job
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed Nov 6, 2024
1 parent 2f231bb commit 987c412
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion data_registry/process_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import logging

from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.db import transaction

Expand Down Expand Up @@ -47,7 +49,8 @@ def process(collection: models.Collection) -> None:
- If it failed temporarily, log the reason
- If it failed permanently, fail the task and end the job
- If all tasks succeeded, end the job and update the collection's active job and last retrieved date.
- If all tasks succeeded, end the job, update the collection's active job and last retrieved date and delete jobs
that are more than a year older than the active job.
In other words, this function advances each job by at most one task. As such, for all tasks of a job to succeed,
this function needs to run at least as many times are there are tasks in the ``JOB_TASKS_PLAN`` setting.
Expand Down Expand Up @@ -119,3 +122,11 @@ def process(collection: models.Collection) -> None:
collection.save()

logger.debug("Job %s has succeeded (%s: %s)", job, country, collection)

jobs_to_delete = collection.job_set.exclude(id=job.id).filter(
end__lt=datetime.datetime.now() - relativedelta(years=1), status=models.Job.Status.COMPLETED
)

for job_to_delete in jobs_to_delete:
job_to_delete.delete()
logger.debug("Old job %s has been deleted (%s: %s)", job_to_delete, country, collection)

0 comments on commit 987c412

Please sign in to comment.