Skip to content
This repository was archived by the owner on Feb 27, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions background_task/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def params(self):
def lock(self, locked_by):
now = datetime_now()
unlocked = Task.objects.unlocked(now).filter(pk=self.pk)
updated = unlocked.update(locked_by=locked_by, locked_at=now)
if updated:
return Task.objects.get(pk=self.pk)
unlocked.update(locked_by=locked_by, locked_at=now)
task = Task.objects.get(pk=self.pk)
if task.locked_by == locked_by:
return task
return None

def _extract_error(self, type, err, tb):
Expand Down