From 7f63cbd14fb00355fb21433da06127e01d1c124c Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 12 Jan 2017 13:22:42 -0500 Subject: [PATCH] Remove `FOR UPDATE` in Queue cancel and complete We have no need for them anymore and it should reduce lock contention a bit Fixes #776 --- data/queue.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/data/queue.py b/data/queue.py index dbdaadb7d..303a2706a 100644 --- a/data/queue.py +++ b/data/queue.py @@ -276,29 +276,11 @@ class WorkQueue(object): """ Attempts to cancel the queue item with the given ID from the queue. Returns true on success and false if the queue item could not be canceled. """ - - with self._transaction_factory(db): - # Load the build queue item for update. - try: - queue_item = db_for_update(QueueItem.select() - .where(QueueItem.id == item_id)).get() - except QueueItem.DoesNotExist: - return False - - # Delete the queue item. - queue_item.delete_instance(recursive=True) - return True + count_removed = QueueItem.delete().where(QueueItem.id == item_id).execute() + return count_removed > 0 def complete(self, completed_item): - with self._transaction_factory(db): - try: - completed_item_obj = self._item_by_id_for_update(completed_item.id) - except QueueItem.DoesNotExist: - self._currently_processing = False - return - - completed_item_obj.delete_instance(recursive=True) - self._currently_processing = False + self._currently_processing = not self.cancel(completed_item.id) def incomplete(self, incomplete_item, retry_after=300, restore_retry=False): with self._transaction_factory(db):