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

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