Skip to content

Commit

Permalink
Ensure retries work are allowed to be queued
Browse files Browse the repository at this point in the history
  • Loading branch information
joealcorn committed Sep 2, 2015
1 parent f493df4 commit 4d47990
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def noop_task(*a, **kw):

# Things to look out for

- Tasks with an ETA or countdown
- Tasks with an ETA, countdown or retry delays
- Unregistered tasks
- Unacknowledged tasks
- Manually purging your broker
Expand Down
4 changes: 4 additions & 0 deletions celery_dedupe/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def apply_async(self, args=None, kwargs=None, **kw):
return super(DedupeTask, self).apply_async(args=args, kwargs=kwargs, **kw)

existing_task_id = self.storage.get(key)
if existing_task_id == task_id:
# This should be a retry, so add it to the broker anyway
return super(DedupeTask, self).apply_async(args=args, kwargs=kwargs, **kw)

app = self._get_app()
if app.conf.CELERY_ALWAYS_EAGER:
warnings.warn('Using DedupeTask in conjunction with CELERY_ALWAYS_EAGER, can not return EagerResult')
Expand Down
11 changes: 11 additions & 0 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def raise_exception(self, *a, **kw):
raise AttributeError()


@task(base=DedupeTask, storage=storage, bind=True)
def retry_task(self, *a, **kw):
if self.request.retries == 0:
self.retry(countdown=0)
return True


class TestDedupeTask(object):

def setup_class(self):
Expand Down Expand Up @@ -64,3 +71,7 @@ def test_key_cleared_on_exception(self):
assert False

assert not redis.exists(key)

def test_task_retry(self):
result = retry_task.delay()
assert result.get()

0 comments on commit 4d47990

Please sign in to comment.