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

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