def update_current_task_status(): with scheduler.app.app_context(): log.debug("Start maintain running task.") print(f"Running task: {current_task_list}") log.info(f"Running task: {current_task_list}") task_list = copy.copy(current_task_list) for task_id, task in task_list.items(): task_status = task.is_alive() if task_status is not True: exit_code = task.exitcode if exit_code == 0: log.info( f"Task[{task_id}] normally finished. exit code:[{exit_code}]" ) update_the_task_status(task_id, TASK_STATUS_FINISHED) let_the_main_node_export_result_to_file(task_id) else: log.info( f"Task[{task_id}] not normally finished. exit code:[{exit_code}]" ) update_the_task_status(task_id, TASK_STATUS_INTERRUPT) let_the_main_node_export_result_to_file(task_id) update_time_info_for_the_task(task_id, "end_time") current_task_list.pop(task_id) update_node_info("cur_ps", len(current_task_list)) node_running_info.update({"cur_ps": len(current_task_list)})
def upload_this_node_info(): # flask_app = create_app('development') # flask_context = flask_app.app_context() # flask_context.push() # delete_the_node_info_conflict_with_me() node_info = generate_node_info() info_db = Node(ip_addr=node_info.get("ip_addr", None), host_name=node_info.get("host_name", None), node_type=node_info.get("node_type", None), max_ps=node_info.get("max_ps", 10), cur_ps=node_info.get("cur_ps", 0), status=node_info.get("status", 0), ps_id=node_info.get("ps_id", 0)) db.session.add(info_db) try: db.session.commit() except ProgrammingError as e: log.error(e) except IntegrityError as e: db.session.rollback() log.error(e) except DataError as e: log.error(e) else: print(f"Get the node id: {info_db.id}") log.info(f"Upload new node id: {info_db.id}") node_running_info.update({"node_id": info_db.id}) print(node_running_info) finally: pass
def init_app(cls, app): log.info("Config flask app as type production.") print("Config flask app as type production.") log.info(cls.SQLALCHEMY_DATABASE_URI) node_running_info.update({"main_node_host": db_config.mysql_host}) Config.init_app(app)
def update_node_running_info(): node_info = generate_node_info() node_running_info.update(node_info)