async def start_sources(msg_service: Service, stop_event: asyncio.Event, config: InstanceConfig): """Start all sources and make them report to message queue""" await asyncio.wait([ AWXApiSource(msg_service.get_client(), instance_config=config).start(stop_event), AWXWebHookSource(msg_service.get_client()).start(stop_event), start_influx_sources(msg_service, stop_event, config) ])
def _main(): service = Service() service.start() try: asyncio.run(_ordered_start(service)) finally: service.stop()
async def start_influx_sources(msg_service: Service, stop_event: asyncio.Event, config: InstanceConfig): await asyncio.wait([ InfluxSource(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceLBTiming(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceLBDOWN(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceLBDOWNFailCount(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceDiskStateRead(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceDiskStateWrite(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceDiskStateReadSFS(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceDiskStateWriteSFS( msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceSFSStatus(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceAutoscaling(msg_service.get_client(), instance_config=config).start(stop_event), InfluxSourceRDSTest(msg_service.get_client(), instance_config=config).start(stop_event) ])
import atexit import logging from apubsub import Service LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) CLG = logging.StreamHandler() CLG.setLevel(logging.DEBUG) LOGGER.addHandler(CLG) SERVICE = Service() SERVICE.start() atexit.register(SERVICE.stop)
async def started_client(service: Service): _clt = service.get_client() await _clt.start_consuming() return _clt
async def test_service_on_another_port(service): srv2 = Service() assert srv2.address != service.address[0], service.address[1] - 110
def service(): srv = Service() srv.start() yield srv srv.stop()