def receive_workflows(self): """Receives requests to execute workflows, and sends them off to worker threads""" logger.info('Starting workflow receiver') box = Box(self.key, self.server_key) while not self.exit: received_message = self.cache.rpop("request_queue") if received_message is not None: try: decrypted_msg = box.decrypt(received_message) except CryptoError: logger.error( 'Worker could not decrypt received workflow message') continue try: message = ExecuteWorkflowMessage() message.ParseFromString(decrypted_msg) except DecodeError: logger.error( 'Workflow could not decode received workflow message') else: start = message.start if hasattr(message, 'start') else None start_arguments = [] if hasattr(message, 'arguments'): for arg in message.arguments: start_arguments.append( Argument(**(MessageToDict( arg, preserving_proto_field_name=True)))) yield message.workflow_id, message.workflow_execution_id, start, start_arguments, message.resume else: yield None raise StopIteration
def receive_requests(self): """Receives requests to execute workflows, and sends them off to worker threads""" self.request_sock.send(b"Ready") while True: message_bytes = self.request_sock.recv() message = ExecuteWorkflowMessage() message.ParseFromString(message_bytes) start = message.start if hasattr(message, 'start') else None start_arguments = [] if hasattr(message, 'arguments'): for arg in message.arguments: start_arguments.append( Argument(**(MessageToDict( arg, preserving_proto_field_name=True)))) self.threadpool.submit(self.execute_workflow_worker, message.workflow_id, message.workflow_execution_id, start, start_arguments, message.resume)