def main(): Config.load_config() sonm_api = init_sonm_api() check_balance(sonm_api) Config.load_prices(sonm_api) init_nodes_state(sonm_api) scheduler = BackgroundScheduler() executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) futures_ = dict() try: scheduler.start() scheduler.add_job(print_state, 'interval', seconds=60, id='print_state') scheduler.add_job(reload_config, 'interval', kwargs={"sonm_api": sonm_api}, seconds=60, id='reload_config') scheduler.add_job(check_balance, 'interval', kwargs={"sonm_api": sonm_api}, seconds=600, id='check_balance') executor.submit(run_http_server) watch(executor, futures_) print_state() logger.info("Work completed") except KeyboardInterrupt: logger.info("Keyboard interrupt, script exiting") except SystemExit as e: logger.exception("System Exit", e) finally: logger.info("Script exiting. Sonm node will continue work") for n in Nodes.get_nodes_arr(): n.stop_work() SonmHttpServer.KEEP_RUNNING = False executor.shutdown(wait=False) scheduler.shutdown(wait=False)
def reload_config(sonm_api: SonmApi): Config.load_config() Config.load_prices(sonm_api) append_missed_nodes(sonm_api, Config.node_configs)