|
@@ -12,10 +12,11 @@ class TaskManager(models.Manager):
|
|
def get_task(self, task_id, exception_retry_count=1):
|
|
def get_task(self, task_id, exception_retry_count=1):
|
|
"""Get task meta for task by ``task_id``.
|
|
"""Get task meta for task by ``task_id``.
|
|
|
|
|
|
- :keyword exception_retry_count: How many times to retry with
|
|
|
|
- transaction rollback on exception. 1 by default: we assume
|
|
|
|
- the pessimistic case when we get race condition in which
|
|
|
|
- task is created by other process during get_or_create
|
|
|
|
|
|
+ :keyword exception_retry_count: How many times to retry by
|
|
|
|
+ transaction rollback on exception. This could theoretically
|
|
|
|
+ happen in a race condition if another worker is trying to
|
|
|
|
+ create the same task. The default is to retry once.
|
|
|
|
+
|
|
"""
|
|
"""
|
|
try:
|
|
try:
|
|
task, created = self.get_or_create(task_id=task_id)
|
|
task, created = self.get_or_create(task_id=task_id)
|
|
@@ -24,7 +25,7 @@ class TaskManager(models.Manager):
|
|
# throw, so we have to catch everything.
|
|
# throw, so we have to catch everything.
|
|
if exception_retry_count > 0:
|
|
if exception_retry_count > 0:
|
|
transaction.rollback_unless_managed()
|
|
transaction.rollback_unless_managed()
|
|
- return self.get_task(task_id, exception_retry_count-1)
|
|
|
|
|
|
+ return self.get_task(task_id, exception_retry_count - 1)
|
|
else:
|
|
else:
|
|
raise
|
|
raise
|
|
return task
|
|
return task
|
|
@@ -57,12 +58,11 @@ class TaskManager(models.Manager):
|
|
:keyword traceback: The traceback at the point of exception (if the
|
|
:keyword traceback: The traceback at the point of exception (if the
|
|
task failed).
|
|
task failed).
|
|
|
|
|
|
- :keyword exception_retry_count: How many times to retry with
|
|
|
|
- transaction rollback on exception. 2 by default: we assume
|
|
|
|
- the pessimistic case when task execution by itself could
|
|
|
|
- leave broken transaction, and during second try we get
|
|
|
|
- race condition in which task is created by other process
|
|
|
|
- during get_or_create
|
|
|
|
|
|
+ :keyword exception_retry_count: How many times to retry by
|
|
|
|
+ transaction rollback on exception. This could theoretically
|
|
|
|
+ happen in a race condition if another worker is trying to
|
|
|
|
+ create the same task. The default is to retry twice.
|
|
|
|
+
|
|
"""
|
|
"""
|
|
try:
|
|
try:
|
|
task, created = self.get_or_create(task_id=task_id, defaults={
|
|
task, created = self.get_or_create(task_id=task_id, defaults={
|