mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-04 18:38:11 +08:00
fix race condition in orm broker
This commit is contained in:
@@ -54,11 +54,10 @@ class ORM(Broker):
|
|||||||
tasks = self.get_connection().filter(key=self.list_key, lock__lt=_timeout())[0:Conf.BULK]
|
tasks = self.get_connection().filter(key=self.list_key, lock__lt=_timeout())[0:Conf.BULK]
|
||||||
if tasks:
|
if tasks:
|
||||||
task_list = []
|
task_list = []
|
||||||
lock = timezone.now()
|
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
task.lock = lock
|
if self.get_connection().filter(id=task.id, lock=task.lock).update(lock=timezone.now()):
|
||||||
task.save(update_fields=['lock'])
|
task_list.append((task.pk, task.payload))
|
||||||
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
|
return task_list
|
||||||
# empty queue, spare the cpu
|
# empty queue, spare the cpu
|
||||||
sleep(Conf.POLL)
|
sleep(Conf.POLL)
|
||||||
|
|||||||
Reference in New Issue
Block a user