Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1777 | celery tasks cleanup job to remove a…
Browse files Browse the repository at this point in the history
…ny task older than 7 days
  • Loading branch information
snyaggarwal committed Apr 29, 2024
1 parent 30cf97d commit 4e402a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
'task': 'core.common.tasks.vacuum_and_analyze_db',
'schedule': crontab(0, 1), # Run at 1 am
},

'expire-celery-tasks': {
'task': 'core.common.tasks.expire_old_celery_tasks',
'schedule': crontab(0, 1), # Run at 1 am
},
}
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
6 changes: 6 additions & 0 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,9 @@ def resolve_url_registry_entries(repo_id, repo_type):
repo = repo_klass.objects.filter(id=repo_id).first()
for entry in repo.active_url_registry_entries:
entry.lookup_entry()


@app.task(ignore_result=True)
def expire_old_celery_tasks():
from core.tasks.models import Task
Task.objects.filter(updated_at__lt=timezone.now() - timezone.timedelta(days=7)).delete()

0 comments on commit 4e402a1

Please sign in to comment.