diff --git a/backend/helpers/threads.py b/backend/helpers/threads.py index 0a4e6ad6c0db9ee9341e9de2704e8903fd9f4829..5679b9863a96959b0601e6b296d491507f1c8d5c 100644 --- a/backend/helpers/threads.py +++ b/backend/helpers/threads.py @@ -21,8 +21,22 @@ def request_provision(): try: provisioning_queue.send("provision", timeout=0) except BusyError: - # If we can't signal for some reason, silently fail. + # If we can't signal for some reason (queue limit reached), silently + # fail. pass def wait_provision(): + # We first wait until there's any message in the queue. provisioning_queue.receive() + # After that, we check if there are any more messages, to prevent a couple + # of (long) provisioning runs to be done back-to-back in case of multiple + # provisioning requests. Note however that if a request comes in during the + # middle of a provisioning run, we still do another one right after to make + # sure we propagate the latest changes right away. + try: + while True: + # We read with zero timeout, so we get an exception right away if + # the queue is empty. + provisioning_queue.receive(timeout=0) + except BusyError: + pass