From 120c490148a025a69500f025cc053db4b3b25a2e Mon Sep 17 00:00:00 2001 From: OhMaley Date: Thu, 24 Nov 2022 09:58:02 -0500 Subject: [PATCH] creation of task --- codalab/apps/web/tasks.py | 12 ++++++++++++ codalab/codalab/settings/base.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/codalab/apps/web/tasks.py b/codalab/apps/web/tasks.py index 5ae2baf23..1eafbd26f 100644 --- a/codalab/apps/web/tasks.py +++ b/codalab/apps/web/tasks.py @@ -965,6 +965,18 @@ def create_storage_analytics_snapshot(): logger.info("Task create_storage_analytics_snapshot stoped. Duration = {:.3f} seconds".format(elapsed_time)) +@task(queue='site-worker') +def reset_computed_storage_analytics(): + logger.info("Task reset_computed_storage_analytics started") + starting_time = time.process_time() + + # Reset the value of all computed sizes so they will be re-computed again without any shifting on the next run of the storage analytics task + CompetitionSubmission.objects.all().update(sub_size=0) + + elapsed_time = time.process_time() - starting_time + logger.info("Task reset_computed_storage_analytics stoped. Duration = {:.3f} seconds".format(elapsed_time)) + + @task(queue='site-worker') def do_phase_migrations(): competitions = Competition.objects.filter(is_migrating=False) diff --git a/codalab/codalab/settings/base.py b/codalab/codalab/settings/base.py index bbfc744ff..99321ae03 100644 --- a/codalab/codalab/settings/base.py +++ b/codalab/codalab/settings/base.py @@ -496,6 +496,10 @@ class Base(Configuration): 'task': 'apps.web.tasks.create_storage_analytics_snapshot', 'schedule': crontab(hour=2, minute=0, day_of_week='sun') # Every Sunday at 02:00 }, + 'reset_computed_storage_analytics': { + 'task': 'apps.web.tasks.reset_computed_storage_analytics', + 'schedule': crontab(minute=0, hour=2, day_of_month=1, month_of_year="*/3") # Every 3 month at 02:00 on the 1st + } } CELERY_TIMEZONE = 'UTC'