def run_in_consumer(mocker, msg: BaseMessage, planner: WorkPlanner, consumer: ConsumerThread, motr: Motr) -> None: mocker.patch.object(planner, 'get_next_command', side_effect=[msg, Die()]) profile = Profile(fid=create_profile_fid(22), name='the_pool', pool_names=['name1']) motr.start('endpoint', create_process_fid(120), create_process_fid(15), profile) consumer._do_work(planner, motr)
def main(): # Note: no logging must happen before this call. # Otherwise the log configuration will not apply. _setup_logging() # [KN] The elements in the queue will appear if # 1. A callback is invoked from ha_link (this will happen in a motr # thread which must be free ASAP) # 2. A new HA notification has come form Consul via HTTP # [KN] The messages are consumed by Python thread created by # _run_thread(ConsumerThread(..)) function. # # [KN] Note: The server is launched in the main thread. q = Queue(maxsize=8) util: ConsulUtil = ConsulUtil() cfg = _get_motr_fids(util) LOG.info('Welcome to HaX') LOG.info(f'Setting up ha_link interface with the options as follows: ' f'hax fid = {cfg.hax_fid}, hax endpoint = {cfg.hax_ep}, ' f'HA fid = {cfg.ha_fid}, RM fid = {cfg.rm_fid}') ffi = HaxFFI() herald = DeliveryHerald() motr = Motr(queue=q, rm_fid=cfg.rm_fid, ffi=ffi, herald=herald) # Note that consumer thread must be started before we invoke motr.start(..) # Reason: hax process will send entrypoint request and somebody needs # to reply it. consumer = _run_thread(ConsumerThread(q, motr)) try: motr.start(cfg.hax_ep, process=cfg.hax_fid, ha_service=cfg.ha_fid, rm_service=cfg.rm_fid) LOG.info('Motr API has been started') service_monitor = _run_thread(ServiceMonitor(q)) stats_updater = _run_thread(FsStatsUpdater(motr, interval_sec=30)) # [KN] This is a blocking call. It will work until the program is # terminated by signal run_server(q, herald, threads_to_wait=[consumer, stats_updater, service_monitor]) except Exception: LOG.exception('Exiting due to an exception') finally: motr.close()
def _run_qconsumer_thread(planner: WorkPlanner, motr: Motr, herald: DeliveryHerald, consul: ConsulUtil, idx: int) -> ConsumerThread: thread = ConsumerThread(planner, motr, herald, consul, idx) thread.start() return thread
def _run_qconsumer_thread(planner: WorkPlanner, motr: Motr, herald: DeliveryHerald, consul: ConsulUtil, idx: int) -> StoppableThread: return _run_thread(ConsumerThread(planner, motr, herald, consul, idx))
def _run_qconsumer_thread(queue: Queue, motr: Motr, herald: DeliveryHerald) -> ConsumerThread: thread = ConsumerThread(queue, motr, herald) thread.start() return thread
def consumer(planner, motr, herald, consul_util): return ConsumerThread(planner, motr, herald, consul_util, 0)
def _run_qconsumer_thread(queue: Queue, motr: Motr) -> ConsumerThread: thread = ConsumerThread(queue, motr) thread.start() return thread