def do_scheduling(): set_initial_role() network_cruft_cleaner() schedule.run_all(1, 'base-tasks') validate_role() node_role = NODE_SETTINGS['node_role'] mode = NODE_SETTINGS['mode'] if node_role is None and mode == 'peer': NODE_SETTINGS['use_localhost'] = True if mode == 'peer': if node_role is None: check_time = 33 baseCheckJob = schedule.every(check_time).seconds baseCheckJob.do(run_net_check).tag('base-tasks', 'route-status') try: data = wait_for_moon(timeout=45) except Exception as exc: logger.error('ENODATA exception {}'.format(exc)) put_state_msg('ERROR') try: handle_moon_data(data) put_state_msg('STARTING') except MemberNodeError as exc: logger.error('ENODATA exception {}'.format(exc)) put_state_msg('ERROR') str_level = logging.getLevelName(logger.getEffectiveLevel()) logger.debug('Current log level is: {}'.format(str_level)) startup_handlers() else: if node_role == 'controller': netobj_q = dc.Deque(directory=get_cachedir('netobj_queue')) gen_netobj_queue(netobj_q) cache = dc.Index(get_cachedir()) for key_str in ['peer', 'moon', 'mstate']: delete_cache_entry(cache, key_str) elif node_role == 'moon': cln_q = dc.Deque(directory=get_cachedir('clean_queue')) pub_q = dc.Deque(directory=get_cachedir('pub_queue')) schedule.every(37).seconds.do(run_cleanup_check, cln_q, pub_q).tag( 'chk-tasks', 'cleanup') schedule.every(15).minutes.do(check_daemon_status).tag( 'chk-tasks', 'responder') schedule.every(15).minutes.do(check_daemon_status, script='msg_subscriber.py').tag( 'chk-tasks', 'subscriber') schedule.run_all(1, 'chk-tasks') elif mode == 'adhoc': logger.debug('Running in adhoc mode...') if NODE_SETTINGS['nwid']: logger.debug('ADHOC: found network {}'.format( NODE_SETTINGS['nwid'])) do_startup(NODE_SETTINGS['nwid']) else: logger.error('No network ID found in NODE_SETTINGS!!') logger.error('Have you created a network yet?') logger.debug('MODE: startup mode is {} and role is {}'.format( mode, node_role)) logger.info( 'You are running fpnd/node_tools version {}'.format(fpnd_version)) while True: schedule.run_pending() time.sleep(1)
def test_startup_handlers(): startup_handlers()