class EventStore: def __init__(self): self.config = Config() self.db = Database(self.config) self.broker = Broker(self.config, self.process_event) async def start_broker(self): await self.broker.start() async def shutdown(self, signal): if signal: log.info(f'Received shutdown signal: {signal}') await self.broker.cancel() async def process_event(self, event, pub_func): """accepts an event and submits it to the datastore for storage. Returns a json string representation of the persisted event.""" log.debug(f'processing event {event}') persisted_events = self.db.commit_event(event) for e in persisted_events: await pub_func(e) log.info('Finished processing event')