diff --git a/HISTORY.rst b/HISTORY.rst index 418cfbc2b5..c47324e0c2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -259,7 +259,9 @@ * Move queue and task registration to the CeleryQueue class. The .queues.py module is now loaded automatically. * Allow setting the Docker user UID and GUID. - +* Add task path validation. + + 3.1.11 (2019-04-XX) =================== * Fix multiple tag selection wizard step. diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index ede4b2cdf0..e2465bc391 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -569,6 +569,7 @@ Other changes * Move queue and task registration to the CeleryQueue class. The .queues.py module is now loaded automatically. * Allow setting the Docker user UID and GUID. +* Add task path validation. Removals diff --git a/mayan/apps/checkouts/queues.py b/mayan/apps/checkouts/queues.py index b98d7b1037..52434b8ad6 100644 --- a/mayan/apps/checkouts/queues.py +++ b/mayan/apps/checkouts/queues.py @@ -16,7 +16,7 @@ queue_checkouts_periodic = CeleryQueue( queue_checkouts_periodic.add_task_type( label=_('Check expired checkouts'), name='task_check_expired_check_outs', - dotted_path='mayan.apps.task_check_expired_check_outs', + dotted_path='mayan.apps.checkouts.tasks.task_check_expired_check_outs', schedule=timedelta( seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL ), diff --git a/mayan/apps/task_manager/classes.py b/mayan/apps/task_manager/classes.py index 40f90a739a..0ee4a1379e 100644 --- a/mayan/apps/task_manager/classes.py +++ b/mayan/apps/task_manager/classes.py @@ -11,6 +11,7 @@ from celery.task.control import inspect from django.apps import apps from django.utils.encoding import force_text, python_2_unicode_compatible +from django.utils.module_loading import import_string from django.utils.timezone import now from mayan.celery import app as celery_app @@ -36,10 +37,21 @@ class TaskType(object): self.dotted_path = dotted_path self.schedule = schedule self.__class__._registry[name] = self + self.validate() def __str__(self): return force_text(self.label) + def validate(self): + try: + import_string(dotted_path=self.dotted_path) + except Exception as exception: + logger.critical( + 'Exception validating task %s; %s', self.label, exception, + exc_info=True + ) + raise + @python_2_unicode_compatible class Task(object): @@ -74,6 +86,7 @@ class CeleryQueue(object): 'Error importing %s queues.py file; %s', app.name, exception ) + raise CeleryQueue.update_celery()