diff --git a/dev/celery/docker-init.sh b/dev/celery/docker-init.sh index 9d00328ad0..9fb1d6324d 100755 --- a/dev/celery/docker-init.sh +++ b/dev/celery/docker-init.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # # Environment parameters: # diff --git a/docker-compose.yml b/docker-compose.yml index 983a0de989..fc09974fe1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,6 +65,7 @@ services: celery: image: ghcr.io/ietf-tools/datatracker-celery:latest + init: true environment: CELERY_APP: ietf CELERY_ROLE: worker @@ -79,20 +80,23 @@ services: - .:/workspace - app-assets:/assets - beat: - image: ghcr.io/ietf-tools/datatracker-celery:latest - environment: - CELERY_APP: ietf - CELERY_ROLE: beat - UPDATE_REQUIREMENTS_FROM: requirements.txt - command: - - '--loglevel=INFO' - depends_on: - - db - restart: unless-stopped - stop_grace_period: 1m - volumes: - - .:/workspace +# Celery Beat is a periodic task runner. It is not normally needed for development, +# but can be enabled by uncommenting the following. +# +# beat: +# image: ghcr.io/ietf-tools/datatracker-celery:latest +# environment: +# CELERY_APP: ietf +# CELERY_ROLE: beat +# UPDATE_REQUIREMENTS_FROM: requirements.txt +# command: +# - '--loglevel=INFO' +# depends_on: +# - db +# restart: unless-stopped +# stop_grace_period: 1m +# volumes: +# - .:/workspace volumes: mariadb-data: diff --git a/ietf/submit/migrations/0010_create_cancel_stale_submissions_task.py b/ietf/submit/migrations/0010_create_cancel_stale_submissions_task.py new file mode 100644 index 0000000000..5d8511054c --- /dev/null +++ b/ietf/submit/migrations/0010_create_cancel_stale_submissions_task.py @@ -0,0 +1,52 @@ +# Generated by Django 2.2.28 on 2022-08-23 08:45 + +from django.db import migrations +from django.utils import timezone + + +def forward(apps, schema_editor): + IntervalSchedule = apps.get_model('django_celery_beat', 'IntervalSchedule') + PeriodicTask = apps.get_model('django_celery_beat', 'PeriodicTask') + PeriodicTasks = apps.get_model('django_celery_beat', 'PeriodicTasks') + every_five_minutes, _ = IntervalSchedule.objects.get_or_create( + every=5, + period='minutes', # in non-migration code, use IntervalSchedule.MINUTES instead + ) + task, _ = PeriodicTask.objects.get_or_create( + interval=every_five_minutes, + name='Cancel stale submissions', + task='ietf.submit.tasks.cancel_stale_submissions', + ) + # this replicates the PeriodicTasks.changed() call as of django-celery-beat==2.3.0 + PeriodicTasks.objects.update_or_create(ident=1, defaults={'last_update': timezone.now()}) + + +def reverse(apps, schema_editor): + IntervalSchedule = apps.get_model('django_celery_beat', 'IntervalSchedule') + PeriodicTask = apps.get_model('django_celery_beat', 'PeriodicTask') + PeriodicTasks = apps.get_model('django_celery_beat', 'PeriodicTasks') + every_five_minutes = IntervalSchedule.objects.get( + every=5, + period='minutes', # in non-migration code, use IntervalSchedule.MINUTES instead + ) + task = PeriodicTask.objects.get( + interval=every_five_minutes, + name='Cancel stale submissions', + task='ietf.submit.tasks.cancel_stale_submissions', + ) + task.delete() + every_five_minutes.delete() + # this replicates the PeriodicTasks.changed() call as of django-celery-beat==2.3.0 + PeriodicTasks.objects.update_or_create(ident=1, defaults={'last_update': timezone.now()}) + + +class Migration(migrations.Migration): + + dependencies = [ + ('submit', '0009_auto_20220427_1223'), + ('django_celery_beat', '0016_alter_crontabschedule_timezone'), + ] + + operations = [ + migrations.RunPython(forward, reverse), + ]