def main(): connect(host="mongodb://27.78.16.56:8040/iron_man") #connect(host="mongodb://27.78.16.56:8040/ironmanV2")# push stringhelpers.print_welcome() socketConnector = SocketConnector(os.environ.get('SOCKBOT_SERVER'), os.environ.get('SOCKBOT_PORT')) dict_sockbot = socketConnector.connect() '''_mega_manager = MegaManager('MEGA-MANAGEMENT', False) _mega_manager.start()''' '''_flask_manager = FlaskManager('FLASK-MANAGEMENT', False) _flask_manager.start()''' _ironman_manager = IronManager('IRONMAN-MANAGEMENT', False, dict_sockbot['io'], dict_sockbot['iron_namespace']) _ironman_manager.start() heartbeat = HeartBeat(False, dict_sockbot['io']) heartbeat.start() dict_sockbot['io'].on('on_startstop_autobot', on_startstop_autobot) #socket waiting response dict_sockbot['io'].wait()
class taskManager: def __init__(self): args = parse_process_args() self.heartbeat = HeartBeat(process_id=getpid()) self.heartbeat.daemon = True atexit.register(self.handle_shutdown) self.flow_manager = FlowManager(cache_prefix=args.execution_group_id, pid=getpid()) self.executor = ExecutionWorker(args.model_path, args.video_path, args.model_config_path, args.code_path) self.merger = Merger(args.video_path, args.model_config_path, args.video_token) self.action_map = { 'merge': self.merger.execute, 'execute': self.executor.execute } def handle_shutdown(self): self.heartbeat.gracefull_shutdown = True logger.info('[TASKMANAGER] Process shutdown successfully') def start(self): self.heartbeat.start() while True: try: job_meta, job_key = self.flow_manager.get_new_job() self.heartbeat.curr_job_id = job_key.decode('utf-8') except Exception as e: logger.exception(f'[TASKMANAGER] job key is malformed : {e}') self.flow_manager.reject_job(job_key) continue self.heartbeat.set_busy() action = self.action_map.get(job_meta['action']) if action: try: action(job_meta) except Exception as e: logger.exception( f'[TASKMANAGER] failed to execute action on job {job_meta.get("jid")} | {e}' ) self.flow_manager.reject_job(job_key) else: logger.warning( f'[TASKMANAGER] action {job_meta.get("action")} not defined | ignoring job' ) self.heartbeat.set_free() self.heartbeat.join()