def delete_interface_many(flow_id_arr, user_id): """批量删除任务流""" err_msg = [] for interface_id in flow_id_arr: # 查询是否在调度内 if InterfaceModel.get_schedule_detail(db.etl_db, interface_id): err_msg.append('任务流ID: [%s], 调度运行中, 请停止调度任务后删除' % interface_id) # 任务流前后置依赖 parent = InterfaceModel.get_interface_parent( db.etl_db, interface_id) child = InterfaceModel.get_interface_child(db.etl_db, interface_id) if parent or child: abort(400, **make_result(status=400, msg='任务流存在前/后置依赖, 不可删除')) # # 查询是否有任务依赖 # ids = InterfaceModel.get_job_prep_by_interface(db.etl_db, interface_id) # job_ids = [] # out_ids = [] # for items in ids: # if items['job_id']: # job_ids.append(items['job_id']) # if items['out_id']: # out_ids.append(items['out_id']) # if set(out_ids) - set(job_ids): # abort(400, **make_result(status=400, msg='任务流中任务作为其他任务依赖, 请停止依赖任务后删除')) # 删除任务流 if not err_msg: condition = '(%s)' % ','.join(str(item) for item in flow_id_arr) InterfaceModel.delete_interface_many(db.etl_db, condition, user_id) return Response(msg=err_msg)
def update_interface_detail(interface_id, interface_name, interface_desc, interface_index, old_parent, parent_interface, run_time, retry, user_id, is_deleted): """修改任务流详情""" # 任务流名称查重 interface_detail = InterfaceModel.get_interface_detail_by_name( db.etl_db, interface_name) if interface_detail and interface_detail[ 'interface_id'] != interface_id: abort(400, **make_result(status=400, msg='任务流名称重复, 已存在数据库中')) # 调度查重 if is_deleted == 1: if InterfaceModel.get_schedule_detail(db.etl_db, interface_id): abort(400, **make_result(status=400, msg='任务流在调度任务中, 不能设置失效')) # 修改任务流 if not run_time: run_time = (date.today() + timedelta(days=-1)).strftime('%Y-%m-%d') InterfaceModel.update_interface_detail(db.etl_db, interface_id, interface_name, interface_desc, interface_index, run_time, retry, user_id, is_deleted) # 修改任务流前置 old_parent = set() if not old_parent else set(old_parent) parent_interface = set() if not parent_interface else set( parent_interface) # 删 del_data = [] for parent_id in old_parent - parent_interface: del_data.append({ 'interface_id': interface_id, 'parent_id': parent_id, 'user_id': user_id, 'update_time': int(time.time()) }) InterfaceModel.delete_job_parent(db.etl_db, del_data) if del_data else None # 增 add_data = [] for parent_id in parent_interface - old_parent: add_data.append({ 'interface_id': interface_id, 'parent_id': parent_id, 'user_id': user_id, 'insert_time': int(time.time()), 'update_time': int(time.time()) }) InterfaceModel.add_job_parent(db.etl_db, add_data) if add_data else None return Response(interface_id=interface_id)
def delete_interface(interface_id, user_id): """删除接口""" # 查询是否在调度内 if InterfaceModel.get_schedule_detail(db.etl_db, interface_id): abort(400, **make_result(status=400, msg='调度任务运行中, 请停止调度任务后删除')) # 查询是否有任务依赖 ids = InterfaceModel.get_job_prep_by_interface(db.etl_db, interface_id) job_ids = [] out_ids = [] for items in ids: if items['job_id']: job_ids.append(items['job_id']) if items['out_id']: out_ids.append(items['out_id']) if set(out_ids) - set(job_ids): abort(400, **make_result(status=400, msg='接口中任务作为其他任务依赖, 请停止依赖任务后删除')) # 删除接口 InterfaceModel.delete_interface(db.etl_db, interface_id, user_id) return Response(interface_id=interface_id)
def delete_interface(interface_id, user_id): """删除任务流""" # 查询是否在调度内 if InterfaceModel.get_schedule_detail(db.etl_db, interface_id): abort(400, **make_result(status=400, msg='调度任务运行中, 请停止调度任务后删除')) # 任务流前后置依赖 parent = InterfaceModel.get_interface_parent(db.etl_db, interface_id) child = InterfaceModel.get_interface_child(db.etl_db, interface_id) if parent or child: abort(400, **make_result(status=400, msg='任务流存在前/后置依赖, 不可删除')) # # 查询是否有任务依赖 # ids = InterfaceModel.get_job_prep_by_interface(db.etl_db, interface_id) # job_ids = [] # out_ids = [] # for items in ids: # if items['job_id']: # job_ids.append(items['job_id']) # if items['out_id']: # out_ids.append(items['out_id']) # if set(out_ids) - set(job_ids): # abort(400, **make_result(status=400, msg='任务流中任务作为其他任务依赖, 请停止依赖任务后删除')) # 删除任务流 InterfaceModel.delete_interface(db.etl_db, interface_id, user_id) return Response(interface_id=interface_id)