Add task path validation

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-05-14 16:42:52 -04:00
parent d338da5491
commit ebf8cbdd62
4 changed files with 18 additions and 2 deletions

View File

@@ -259,7 +259,9 @@
* Move queue and task registration to the CeleryQueue class. * Move queue and task registration to the CeleryQueue class.
The .queues.py module is now loaded automatically. The .queues.py module is now loaded automatically.
* Allow setting the Docker user UID and GUID. * Allow setting the Docker user UID and GUID.
* Add task path validation.
3.1.11 (2019-04-XX) 3.1.11 (2019-04-XX)
=================== ===================
* Fix multiple tag selection wizard step. * Fix multiple tag selection wizard step.

View File

@@ -569,6 +569,7 @@ Other changes
* Move queue and task registration to the CeleryQueue class. * Move queue and task registration to the CeleryQueue class.
The .queues.py module is now loaded automatically. The .queues.py module is now loaded automatically.
* Allow setting the Docker user UID and GUID. * Allow setting the Docker user UID and GUID.
* Add task path validation.
Removals Removals

View File

@@ -16,7 +16,7 @@ queue_checkouts_periodic = CeleryQueue(
queue_checkouts_periodic.add_task_type( queue_checkouts_periodic.add_task_type(
label=_('Check expired checkouts'), label=_('Check expired checkouts'),
name='task_check_expired_check_outs', 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( schedule=timedelta(
seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL
), ),

View File

@@ -11,6 +11,7 @@ from celery.task.control import inspect
from django.apps import apps from django.apps import apps
from django.utils.encoding import force_text, python_2_unicode_compatible 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 django.utils.timezone import now
from mayan.celery import app as celery_app from mayan.celery import app as celery_app
@@ -36,10 +37,21 @@ class TaskType(object):
self.dotted_path = dotted_path self.dotted_path = dotted_path
self.schedule = schedule self.schedule = schedule
self.__class__._registry[name] = self self.__class__._registry[name] = self
self.validate()
def __str__(self): def __str__(self):
return force_text(self.label) 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 @python_2_unicode_compatible
class Task(object): class Task(object):
@@ -74,6 +86,7 @@ class CeleryQueue(object):
'Error importing %s queues.py file; %s', app.name, 'Error importing %s queues.py file; %s', app.name,
exception exception
) )
raise
CeleryQueue.update_celery() CeleryQueue.update_celery()