/** * 文件任务入口 * @param int $ap_id * @param array $data * @param array $options * @param int $task_id * @return array */ static function run_task_by_ap_id_and_record($ap_id, $data = [], $options = [], $task_id = null) { // get ap info $ap_manager = Module_ControlCentre_ApManager::get_instance()->set_current_ap($ap_id); if (empty($ap_manager)) { return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_GET_ACCESS_POINT_FAILD, 'Get ap failed! Result:' . Lib_Helper::format_err_struct($ap_id)); } $task_model = new Model_Task(); $nearest_task = $task_model->get_nearest_task_by_ap_id($ap_id, null, ['status', 'create_time']); if ($nearest_task[Const_DataAccess::MREK_ERRNO] != Const_Err_Base::ERR_OK) { return $nearest_task; } $nearest_task = $nearest_task[Const_DataAccess::MREK_DATA]; $ap_info = $ap_manager->get_current_ap(); if (!empty($nearest_task)) { if (isset($nearest_task['status']) && $nearest_task['status'] == self::TASK_STATUS_RUNNING) { $msg = self::_pre_task_running_mail_msg($ap_info, $nearest_task); $people = Module_ControlCentre_ApManager::interface_people(false); empty($people) || Da\Sys_App::run_in_mode(['Module_Notification_Mail', 'send_mail'], [implode(';', $people), '接入点[' . $ap_id . ']任务运行失败', $msg]); return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_TASK_STATUS, 'pre-task is running!'); } } // get flow info $flow_id = $ap_info[Module_FlowManager_Main::KEY_FLOW_ID]; $flow_manager = Module_ControlCentre_FlowManager::get_instance()->set_current_flow($flow_id); if (empty($flow_manager)) { return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_FLOW_NOT_EXISTS, '流程[' . $flow_id . ']不存在'); } $flow_options = []; if (isset($options[Const_DataAccess::RUN_OPTION_FLOW_INFO])) { $flow_options = $options[Const_DataAccess::RUN_OPTION_FLOW_INFO]; if (isset($flow_options[Module_FlowManager_Main::RUN_MODE])) { $run_mode = $flow_options[Module_FlowManager_Main::RUN_MODE]; $flow_manager->set_run_mode($run_mode); } if (isset($flow_options[Module_FlowManager_Main::RUN_OPTION_CUSTOM_FLOW])) { $custom_flow = $flow_options[Module_FlowManager_Main::RUN_OPTION_CUSTOM_FLOW]; $flow_manager->custom_flow($custom_flow); } } empty($flow_options) || $flow_manager->custom_options($flow_options); // end process current flow $options[Const_DataAccess::RUN_OPTION_FLOW_ID] = intval($flow_id); //$options[Const_DataAccess::RUN_OPTION_ACCESS_POINT_INFO] = $ap_info; isset($ap_info[Module_AccessPoint_Main::FIELD_SOURCE_ID]) && ($options[Const_DataAccess::RUN_OPTION_SRC_ID] = $ap_info[Module_AccessPoint_Main::FIELD_SOURCE_ID]); self::get_instance()->create_task($task_id); Module_ControlCentre_Counter::enable(); self::_add_task_record_hook($options); self::_add_module_prepare_to_run_hook(); self::_add_module_record_hook(); self::_add_flow_stat_hook(); self::_add_module_ratio_hook(); Da\Sys_App::run_in_mode(function () { self::_add_failed_mail_hook(); }); return self::get_instance()->run_current_task($data, $options); }