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

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