-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically add check_processing_services_online periodic task
- Loading branch information
1 parent
37a0541
commit 1aba218
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
ami/main/migrations/0045_add_processing_services_status_check_celery_beat_task.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.db import migrations | ||
from django_celery_beat.models import PeriodicTask, CrontabSchedule | ||
|
||
|
||
def create_periodic_task(apps, schema_editor): | ||
crontab_schedule, _ = CrontabSchedule.objects.get_or_create( | ||
minute="*/5", # Every 5 minutes | ||
hour="*", # Every hour | ||
day_of_week="*", # Every day | ||
day_of_month="*", # Every day of month | ||
month_of_year="*", # Every month | ||
) | ||
|
||
PeriodicTask.objects.get_or_create( | ||
name="celery.check_processing_services_online", | ||
task="ami.tasks.check_processing_services_online", | ||
crontab=crontab_schedule, | ||
) | ||
|
||
|
||
def delete_periodic_task(apps, schema_editor): | ||
# Delete the task if rolling back | ||
PeriodicTask.objects.filter(name="celery.check_processing_services_online").delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("main", "0044_merge_20250124_2333"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_periodic_task, delete_periodic_task), | ||
] |