Blame SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch

4d5c3e
From 99437c7cf5811b3840d6138227724a702c0812bb Mon Sep 17 00:00:00 2001
4d5c3e
From: Derek Horton <dehort@redhat.com>
4d5c3e
Date: Fri, 5 Aug 2022 15:02:37 -0500
4d5c3e
Subject: [PATCH] Use thread.join(timeout) to avoid busy waiting and simplify
4d5c3e
 interval event posting logic
4d5c3e
4d5c3e
Resolves: rhbz#2137008
4d5c3e
4d5c3e
(cherry picked from commit 478930cca7a8d4acf21aef0715e42052315cb24e)
4d5c3e
---
4d5c3e
 rhc_worker_playbook/server.py | 12 +++---------
4d5c3e
 1 file changed, 3 insertions(+), 9 deletions(-)
4d5c3e
4d5c3e
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
4d5c3e
index 8e9826f..e41482d 100644
4d5c3e
--- a/rhc_worker_playbook/server.py
4d5c3e
+++ b/rhc_worker_playbook/server.py
4d5c3e
@@ -231,20 +231,14 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
4d5c3e
             artifact_dir=RUNNER_ARTIFACTS_DIR,
4d5c3e
             rotate_artifacts=RUNNER_ROTATE_ARTIFACTS)
4d5c3e
 
4d5c3e
-        # initialize elapsed counter
4d5c3e
-        elapsedTime = 0
4d5c3e
-        startTime = time.time()
4d5c3e
+        # wait for the thread to finish
4d5c3e
         while runnerThread.is_alive():
4d5c3e
-            time.sleep(1)
4d5c3e
-            elapsedTime = time.time() - startTime
4d5c3e
-            if elapsedTime >= response_interval:
4d5c3e
+            runnerThread.join(response_interval)
4d5c3e
+            if runnerThread.is_alive():
4d5c3e
                 # hit the interval, post events
4d5c3e
                 _log("Hit the response interval. Posting current status...")
4d5c3e
                 returnedEvents = _composeDispatcherMessage(events, return_url, response_to)
4d5c3e
                 response = self.dispatcher.Send(returnedEvents)
4d5c3e
-                # reset interval timer
4d5c3e
-                elapsedTime = 0
4d5c3e
-                startTime = time.time()
4d5c3e
 
4d5c3e
         if runner.status == 'failed':
4d5c3e
             # last event sould be the failure, find the reason