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

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