>From 1c8d2b943b91b7ab01e2acf537a45f6cbf7a7025 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Mon, 6 Mar 2023 20:04:13 +1100 Subject: [PATCH] Use newer celery `shared_task` API to support celery > 4.3 --- mediagoblin/media_types/video/processing.py | 6 ++--- mediagoblin/notifications/task.py | 30 +++++++++------------ mediagoblin/processing/task.py | 2 +- mediagoblin/submit/task.py | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index ca7e801c..779fab9b 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -173,7 +173,7 @@ def store_metadata(media_entry, metadata): media_entry.media_data_init(orig_metadata=stored_metadata) -@celery.task() +@celery.shared_task() def main_task(entry_id, resolution, medium_size, **process_info): """ Main celery task to transcode the video to the default resolution @@ -197,7 +197,7 @@ def main_task(entry_id, resolution, medium_size, **process_info): _log.debug('MediaEntry processed') -@celery.task() +@celery.shared_task() def complementary_task(entry_id, resolution, medium_size, **process_info): """ Side celery task to transcode the video to other resolutions @@ -213,7 +213,7 @@ def complementary_task(entry_id, resolution, medium_size, **process_info): entry.id, medium_size)) -@celery.task() +@celery.shared_task() def processing_cleanup(entry_id): _log.debug('Entered processing_cleanup') entry, manager = get_entry_and_processing_manager(entry_id) diff --git a/mediagoblin/notifications/task.py b/mediagoblin/notifications/task.py index 8b300cc8..7072ccb3 100644 --- a/mediagoblin/notifications/task.py +++ b/mediagoblin/notifications/task.py @@ -16,8 +16,7 @@ import logging -from celery import registry -from celery.task import Task +import celery from mediagoblin.tools.mail import send_email from mediagoblin.db.models import Notification @@ -26,21 +25,18 @@ from mediagoblin.db.models import Notification _log = logging.getLogger(__name__) -class EmailNotificationTask(Task): - ''' - Celery notification task. +@celery.shared_task() +def email_notification_task(notification_id, message): + """Celery notification task. This task is executed by celeryd to offload long-running operations from the web server. - ''' - def run(self, notification_id, message): - cn = Notification.query.filter_by(id=notification_id).first() - _log.info(f'Sending notification email about {cn}') - - return send_email( - message['from'], - [message['to']], - message['subject'], - message['body']) - -email_notification_task = registry.tasks[EmailNotificationTask.name] + """ + cn = Notification.query.filter_by(id=notification_id).first() + _log.info(f'Sending notification email about {cn}') + + return send_email( + message['from'], + [message['to']], + message['subject'], + message['body']) diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index 9e4efad1..0425538c 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -31,7 +31,7 @@ logging.basicConfig() _log.setLevel(logging.DEBUG) -@celery.task(default_retry_delay=2 * 60) +@celery.shared_task(default_retry_delay=2 * 60) def handle_push_urls(feed_url): """Subtask, notifying the PuSH servers of new content diff --git a/mediagoblin/submit/task.py b/mediagoblin/submit/task.py index 4ebde502..0b8a3ca2 100755 --- a/mediagoblin/submit/task.py +++ b/mediagoblin/submit/task.py @@ -20,7 +20,7 @@ import pytz from mediagoblin.db.models import MediaEntry -@celery.task() +@celery.shared_task() def collect_garbage(): """ Garbage collection to clean up media -- 2.39.1