-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from dandi/scheduled-draft-manifests
Scheduled draft manifests
- Loading branch information
Showing
7 changed files
with
55 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
release: ./manage.py migrate | ||
web: gunicorn --bind 0.0.0.0:$PORT dandiapi.wsgi | ||
worker: REMAP_SIGTERM=SIGQUIT celery --app dandiapi.celery worker --loglevel INFO | ||
# We are using the -B flag to launch the beat scheduler within the worker thread | ||
# This means that we cannot have multiple workers, as they would all trigger beat events | ||
# The alternative would be a separate worker to drive the beat, which is costly at our current Heroku dyno tier | ||
worker: REMAP_SIGTERM=SIGQUIT celery --app dandiapi.celery worker --loglevel INFO -B |
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,32 @@ | ||
""" | ||
Define and register any scheduled celery tasks. | ||
This module is imported from celery.py in a post-app-load hook. | ||
""" | ||
|
||
from celery import shared_task | ||
from celery.schedules import crontab | ||
from celery.utils.log import get_task_logger | ||
from django.db.transaction import atomic | ||
|
||
from dandiapi.api.models import Version | ||
from dandiapi.api.tasks import write_manifest_files | ||
|
||
logger = get_task_logger(__name__) | ||
|
||
|
||
@shared_task | ||
@atomic | ||
def write_draft_manifest_files(): | ||
logger.info('Writing manifest files for all draft versions') | ||
# TODO Optimize this if it causes too much load in production. | ||
# Rewriting every draft manifest every time is guaranteed not to miss any changes, | ||
# so just do that for now to avoid the complexity involved with modification dates. | ||
for draft_version in Version.objects.filter(version='draft').all(): | ||
write_manifest_files.delay(draft_version.id) | ||
|
||
|
||
def register_scheduled_tasks(sender, **kwargs): | ||
"""Register tasks with a celery beat schedule.""" | ||
# Write out all draft manifests every day at 1 AM | ||
sender.add_periodic_task(crontab(hour=1), write_draft_manifest_files.s()) |
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
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
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
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
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