-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
from celery import Task | ||
|
||
from .redis_sentinel import ensure_redis_call | ||
|
||
|
||
class EnsuredRedisTask(Task): | ||
""" | ||
Abstract celery task subclass which provides same functionality as | ||
:py:class:`ensure_redis_call <celery_redis_sentinel.redis_sentinel.ensure_redis_call>` | ||
except it is added at task definition time instead of during task schedule call. | ||
This task subclass can be provided during task definition | ||
by using ``base`` parameter. | ||
Examples | ||
-------- | ||
:: | ||
@app.task(base=EnsuredRedisTask) | ||
def add(a, b): | ||
return a + b | ||
""" | ||
abstract = True | ||
|
||
def apply_async(self, *args, **kwargs): | ||
_super = super(EnsuredRedisTask, self).apply_async | ||
return ensure_redis_call(_super, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
celery_redis_sentinel.task module | ||
================================= | ||
|
||
.. automodule:: celery_redis_sentinel.task | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
import mock | ||
|
||
from celery_redis_sentinel.task import EnsuredRedisTask | ||
|
||
|
||
@mock.patch('celery_redis_sentinel.task.ensure_redis_call') | ||
def test_apply_async(mock_ensure_redis_call): | ||
task = EnsuredRedisTask() | ||
|
||
actual = task.apply_async('foo', happy='rainbows') | ||
|
||
assert actual == mock_ensure_redis_call.return_value | ||
mock_ensure_redis_call.assert_called_once_with(mock.ANY, 'foo', happy='rainbows') |