Skip to content

Commit

Permalink
Merge pull request #2 from debonzi/stage
Browse files Browse the repository at this point in the history
Raises proper exception if target task is not found.
  • Loading branch information
debonzi committed Aug 15, 2018
2 parents c633781 + 6349764 commit 65b5bba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions crossover/__init__.py
Expand Up @@ -11,16 +11,20 @@
CROSSOVER_ROUTER_NAME = "__crossover_router_dispatch__"


class TaskNotFoundError(Exception):
""" Raised when requested task is not found."""

class CrossoverRouter(celery.Task):
CELERY_4_VERSION = celery.version_info_t(4, 0, 0, '', '')
name = CROSSOVER_ROUTER_NAME

def run(self, *args, **kwargs):
app = celery.current_app if celery.VERSION < self.CELERY_4_VERSION else self.app
task_name = kwargs.pop('task_name')
logger.debug('Got Crossover task: {}'.format(task_name))
_task = celery.current_app.tasks.get(task_name)
_task = app.tasks.get(task_name)
if not _task:
logger.error('Task {0} not found!'.format(task_name))
return
raise TaskNotFoundError('Task "{0}" not found!'.format(task_name))
return _task.delay(*args, **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -21,7 +21,7 @@


setup(name='celery-crossover',
version='1.1.8',
version='1.1.9',
description='Celery Crossover aims to make it really easy to execute tasks in another service.',
author='Daniel Debonzi',
author_email='debonzi@gmail.com',
Expand Down

0 comments on commit 65b5bba

Please sign in to comment.