Blame SOURCES/0001-fix-Execute-playbook-asynchronously.patch

ca7712
From 701885f0f7173f2b0ae113618d15c9f73e9522d2 Mon Sep 17 00:00:00 2001
ca7712
From: Link Dupont <link@sub-pop.net>
ca7712
Date: Wed, 5 May 2021 14:10:49 -0400
ca7712
Subject: [PATCH] fix: Execute playbook asynchronously
ca7712
ca7712
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.
ca7712
ca7712
Resolves: rhbz#2020426
ca7712
ca7712
(cherry picked from commit 332d28d1bb636a5dc8ff5ddf3da8359a9a78b297)
ca7712
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
ca7712
---
ca7712
 rhc_worker_playbook/server.py | 10 +++++++---
ca7712
 1 file changed, 7 insertions(+), 3 deletions(-)
ca7712
ca7712
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
ca7712
index 985ea98..8fa393f 100644
ca7712
--- a/rhc_worker_playbook/server.py
ca7712
+++ b/rhc_worker_playbook/server.py
ca7712
@@ -16,6 +16,7 @@ import time
ca7712
 import json
ca7712
 import uuid
ca7712
 import atexit
ca7712
+import asyncio
ca7712
 from subprocess import Popen, PIPE
ca7712
 from requests import Request
ca7712
 from concurrent import futures
ca7712
@@ -135,9 +136,13 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
ca7712
         '''
ca7712
         Act on messages sent to the WorkerService
ca7712
         '''
ca7712
-        # we have received it
ca7712
-        yggdrasil_pb2.Receipt()
ca7712
 
ca7712
+        loop = asyncio.new_event_loop()
ca7712
+        loop.run_until_complete(self._run_data(request))
ca7712
+
ca7712
+        return yggdrasil_pb2.Receipt()
ca7712
+
ca7712
+    async def _run_data(self, request):
ca7712
         # load configuration
ca7712
         config = _loadConfig()
ca7712
 
ca7712
@@ -256,7 +261,6 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
ca7712
         _log("Posting events...")
ca7712
         response = self.dispatcher.Send(returnedEvents)
ca7712
         _log("Post complete.")
ca7712
-        return
ca7712
 
ca7712
 def serve():
ca7712
     # load config to get directive