data.queue: fix race condition
It's possible that multiple consumers will acquire a queue item if they race on an expired item. To mitigate this, we check that the processing_expires time hasn't been changed since we last read.
This commit is contained in:
parent
609f4fccd8
commit
64d0c5b675
1 changed files with 2 additions and 1 deletions
|
@ -184,7 +184,8 @@ class WorkQueue(object):
|
|||
processing_expires=now + timedelta(seconds=processing_time),
|
||||
retries_remaining=QueueItem.retries_remaining-1)
|
||||
.where(QueueItem.id == db_item.id))
|
||||
changed_query = self._available_jobs_where(set_unavailable_query, now)
|
||||
changed_query = (self._available_jobs_where(set_unavailable_query, now)
|
||||
.where(QueueItem.processing_expires == db_item.processing_expires))
|
||||
changed = changed_query.execute()
|
||||
if changed == 1:
|
||||
item = AttrDict({
|
||||
|
|
Reference in a new issue