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:
Jimmy Zelinskie 2016-07-14 14:53:16 -04:00
parent 609f4fccd8
commit 64d0c5b675

View file

@ -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({