Add task path validation
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -259,6 +259,8 @@
|
||||
* 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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
),
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user