async def setup(self): self.engine = Engine(loop=self.loop) asyncio.ensure_future(self.reload_from_storage()) for topic in self.topics: asyncio.ensure_future(self.bus.subscribe( topic, self.workflow_event )) # Enable workflow exec follow-up get_broker().register(self.report_workflow, topic=EXEC_TOPIC) # Set workflow serializer self.websocket.serializer = serialize_wflow_exec
async def setup(self): self.storage.configure(**self.mongo_config) # Blocks until connection to Mongo is done. await self.storage.index() await run_migrations(**self.mongo_config) selector = WorkflowSelector(self.storage) self.engine = Engine(selector=selector, loop=self.loop) for topic in self.topics: asyncio.ensure_future(self.bus.subscribe( topic, self.workflow_event )) # Enable workflow exec follow-up get_broker().register(self.report_workflow, topic=EXEC_TOPIC) # Handle distributed workflow's failures if 'raft' in self._services.all: self.raft.register('failures', self.failure_handler)
def register_async_handler(self, async_topic, wflow): broker = get_broker() async def exec_handler(event): # Pass if event does not concern this workflow execution if event.source._workflow_exec_id != wflow.uid: return # Publish the event's data # TODO: Beware of unserializable objects asyncio.ensure_future( self.nyuki.bus.publish(event.data, topic=async_topic)) # If the workflow is in a final state, unregister if event.data['type'] in [ WorkflowExecState.end.value, WorkflowExecState.error.value ]: broker.unregister(exec_handler, topic=EXEC_TOPIC) broker.register(exec_handler, topic=EXEC_TOPIC)
def register_async_handler(self, async_topic, events, wflow): broker = get_broker() topic = '/'.join((EXEC_TOPIC, wflow.uid)) if events: events = events.split(',') async def exec_handler(event): # Publish the event's data if requested. if not events or event.data['type'] in events: await self.nyuki.bus.publish(event.data, async_topic) # If the workflow is in a final state, unregister if event.data['type'] in [ WorkflowExecState.END.value, WorkflowExecState.ERROR.value ]: broker.unregister(exec_handler, topic=topic) broker.register(exec_handler, topic=topic)
def register_async_handler(self, async_topic, wflow): broker = get_broker() async def exec_handler(event): # Pass if event does not concern this workflow execution if event.source._workflow_exec_id != wflow.uid: return # Publish the event's data # TODO: Beware of unserializable objects asyncio.ensure_future(self.nyuki.bus.publish( event.data, topic=async_topic )) # If the workflow is in a final state, unregister if event.data['type'] in [ WorkflowExecState.end.value, WorkflowExecState.error.value ]: broker.unregister(exec_handler, topic=EXEC_TOPIC) broker.register(exec_handler, topic=EXEC_TOPIC)