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

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