Skip to content

Commit

Permalink
chore: create stale submission cleanup task and other deployment twea…
Browse files Browse the repository at this point in the history
…ks (#4358)

* chore: disable beat container for dev

* chore: use init option with celery container

* chore: create cancel_stale_submissions task via migration

* chore: revert accidental change included in last commit

* chore: terminate celery docker-init.sh on failed command
  • Loading branch information
jennifer-richards authored Aug 24, 2022
1 parent bd6d19e commit 727feab
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dev/celery/docker-init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
#
# Environment parameters:
#
Expand Down
32 changes: 18 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ services:

celery:
image: ghcr.io/ietf-tools/datatracker-celery:latest
init: true
environment:
CELERY_APP: ietf
CELERY_ROLE: worker
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit 727feab

Please sign in to comment.