diff --git a/SOURCES/0001-fix-Execute-playbook-asynchronously.patch b/SOURCES/0001-fix-Execute-playbook-asynchronously.patch
index 4c59b30..ef50446 100644
--- a/SOURCES/0001-fix-Execute-playbook-asynchronously.patch
+++ b/SOURCES/0001-fix-Execute-playbook-asynchronously.patch
@@ -1,9 +1,14 @@
-From 332d28d1bb636a5dc8ff5ddf3da8359a9a78b297 Mon Sep 17 00:00:00 2001
+From 701885f0f7173f2b0ae113618d15c9f73e9522d2 Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Wed, 5 May 2021 14:10:49 -0400
Subject: [PATCH] fix: Execute playbook asynchronously
Run the playbook code in a coroutine that's scheduled onto a new event loop. Return a protobuf.Receipt message in the WorkerService Send implementation.
+
+Resolves: rhbz#2020426
+
+(cherry picked from commit 332d28d1bb636a5dc8ff5ddf3da8359a9a78b297)
+Signed-off-by: Gael Chamoulaud (Strider)
---
rhc_worker_playbook/server.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
@@ -44,6 +49,3 @@ index 985ea98..8fa393f 100644
def serve():
# load config to get directive
---
-2.35.1
-
diff --git a/SOURCES/0002-Do-not-busy-wait-when-playbook-is-running.patch b/SOURCES/0002-Do-not-busy-wait-when-playbook-is-running.patch
new file mode 100644
index 0000000..e36c880
--- /dev/null
+++ b/SOURCES/0002-Do-not-busy-wait-when-playbook-is-running.patch
@@ -0,0 +1,24 @@
+From dba168bf7e00de5b534603019efa513cfa053716 Mon Sep 17 00:00:00 2001
+From: Jeremy Audet
+Date: Thu, 4 Aug 2022 17:38:51 -0400
+Subject: [PATCH] Do not busy-wait when playbook is running
+
+Resolves: rhbz#2104199
+
+(cherry picked from commit 579a67fba5ea60543a72b118e5644206c6ba720b)
+---
+ rhc_worker_playbook/server.py | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
+index 8fa393f..8e9826f 100644
+--- a/rhc_worker_playbook/server.py
++++ b/rhc_worker_playbook/server.py
+@@ -235,6 +235,7 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
+ elapsedTime = 0
+ startTime = time.time()
+ while runnerThread.is_alive():
++ time.sleep(1)
+ elapsedTime = time.time() - startTime
+ if elapsedTime >= response_interval:
+ # hit the interval, post events
diff --git a/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch b/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch
new file mode 100644
index 0000000..154792d
--- /dev/null
+++ b/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch
@@ -0,0 +1,41 @@
+From aa77652e8ec5d7cbe14e09133e58a45d92cf3720 Mon Sep 17 00:00:00 2001
+From: Derek Horton
+Date: Fri, 5 Aug 2022 15:02:37 -0500
+Subject: [PATCH] Use thread.join(timeout) to avoid busy waiting and simplify
+ interval event posting logic
+
+Resolves: rhbz#2137005
+
+(cherry picked from commit 478930cca7a8d4acf21aef0715e42052315cb24e)
+---
+ rhc_worker_playbook/server.py | 12 +++---------
+ 1 file changed, 3 insertions(+), 9 deletions(-)
+
+diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
+index 8e9826f..e41482d 100644
+--- a/rhc_worker_playbook/server.py
++++ b/rhc_worker_playbook/server.py
+@@ -231,20 +231,14 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
+ artifact_dir=RUNNER_ARTIFACTS_DIR,
+ rotate_artifacts=RUNNER_ROTATE_ARTIFACTS)
+
+- # initialize elapsed counter
+- elapsedTime = 0
+- startTime = time.time()
++ # wait for the thread to finish
+ while runnerThread.is_alive():
+- time.sleep(1)
+- elapsedTime = time.time() - startTime
+- if elapsedTime >= response_interval:
++ runnerThread.join(response_interval)
++ if runnerThread.is_alive():
+ # hit the interval, post events
+ _log("Hit the response interval. Posting current status...")
+ returnedEvents = _composeDispatcherMessage(events, return_url, response_to)
+ response = self.dispatcher.Send(returnedEvents)
+- # reset interval timer
+- elapsedTime = 0
+- startTime = time.time()
+
+ if runner.status == 'failed':
+ # last event sould be the failure, find the reason
diff --git a/SPECS/rhc-worker-playbook.spec b/SPECS/rhc-worker-playbook.spec
index 1f8cdbf..cb56e96 100644
--- a/SPECS/rhc-worker-playbook.spec
+++ b/SPECS/rhc-worker-playbook.spec
@@ -5,13 +5,18 @@
Name: rhc-worker-playbook
Summary: Red Hat connect worker for launching Ansible Runner
Version: 0.1.8
-Release: 1%{?dist}
+Release: 4%{?dist}
License: GPLv2+
Source: rhc-worker-playbook-0.1.8.tar.gz
Source1: https://github.com/ansible-collections/community.general/archive/%{community_general_version}/ansible-collection-community-general-%{community_general_version}.tar.gz
Source2: https://github.com/ansible-collections/ansible.posix/archive/%{ansible_posix_version}/ansible-collection-ansible-posix-%{ansible_posix_version}.tar.gz
-Patch0001: 0001-fix-Execute-playbook-asynchronously.patch
+#
+# patches_ignore=DROP-IN-RPM
+# patches_base=8ddc5ccfc97290a021b4c4de673b92fedc38cbfb
+Patch0001: 0001-fix-Execute-playbook-asynchronously.patch
+Patch0002: 0002-Do-not-busy-wait-when-playbook-is-running.patch
+Patch0003: 0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch
ExclusiveArch: %{go_arches}
@@ -34,7 +39,11 @@ Python-based worker for Red Hat connect, used to launch Ansible playbooks via An
%prep
%setup -q -a1 -a2 -n %{name}-%{version}
+
%patch0001 -p1
+%patch0002 -p1
+%patch0003 -p1
+
pushd community.general-%{community_general_version}
rm -vr .github .azure-pipelines
rm -rvf tests/
@@ -101,6 +110,16 @@ mkdir -p %{buildroot}%{_localstatedir}/log/rhc-worker-playbook/ansible
%doc
%changelog
+* Sat Oct 22 2022 Gael Chamoulaud 0.1.8-4
+- Use thread.join(timeout) to avoid busy waiting and simplify interval event posting logic (rhbz#2137005)
+
+* Fri Aug 05 2022 Gael Chamoulaud 0.1.8-3
+- Do not busy-wait when playbook is running (rhbz#2104199)
+
+* Mon Mar 14 2022 Gaël Chamoulaud - 0.1.8-2
+- Update patches
+- Add DROP-IN-RPM patches_ignore rule for rdopkg
+
* Mon Feb 21 2022 Gaël Chamoulaud - 0.1.8-1
- Patch to fix Execute Playbook Asynchronously (RHBZ#2020426)