Skip to content

Commit

Permalink
introduce bypass_herd_avoidance attribute to skip herd check
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Pendleton committed Mar 16, 2016
1 parent cce2e36 commit 410d735
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions jobtastic/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class JobtasticTask(Task):
front-end code so that users know what to expect.
"""
abstract = True
bypass_herd_avoidance = False

@classmethod
def delay_or_eager(self, *args, **kwargs):
Expand Down Expand Up @@ -238,11 +239,12 @@ def apply_async(self, args, kwargs, **options):
'Found existing cached and completed task: %s', task_id)
return self.AsyncResult(task_id)

# Check for an in-progress equivalent task to avoid duplicating work
task_id = cache.get('herd:%s' % cache_key)
if task_id:
logging.info('Found existing in-progress task: %s', task_id)
return self.AsyncResult(task_id)
if not self.bypass_herd_avoidance:
# Check for an in-progress equivalent task to avoid duplicating work
task_id = cache.get('herd:%s' % cache_key)
if task_id:
logging.info('Found existing in-progress task: %s', task_id)
return self.AsyncResult(task_id)

# It's not cached and it's not already running. Use an atomic lock to
# start the task, ensuring there isn't a race condition that could
Expand Down

0 comments on commit 410d735

Please sign in to comment.