Skip to content

Commit

Permalink
Merge pull request #213 from yannpom/master
Browse files Browse the repository at this point in the history
fix a race condition in orm broker
  • Loading branch information
Koed00 authored Dec 5, 2016
2 parents 82c48cd + bbd2e82 commit 571676e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions django_q/brokers/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def dequeue(self):
tasks = self.get_connection().filter(key=self.list_key, lock__lt=_timeout())[0:Conf.BULK]
if tasks:
task_list = []
lock = timezone.now()
for task in tasks:
task.lock = lock
task.save(update_fields=['lock'])
task_list.append((task.pk, task.payload))
if self.get_connection().filter(id=task.id, lock=task.lock).update(lock=timezone.now()):
task_list.append((task.pk, task.payload))
# else don't process, as another cluster has been faster than us on that task
return task_list
# empty queue, spare the cpu
sleep(Conf.POLL)
Expand Down

0 comments on commit 571676e

Please sign in to comment.