/** * 文件任务入口 * @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); }
/** * @param int $task_id * @param array $data */ static function failed_send_mail_hook($task_id, $data) { if (!isset($data[Const_DataAccess::MREK_ERRNO]) || $data[Const_DataAccess::MREK_ERRNO] !== Const_Err_Base::ERR_OK) { $status = isset($data[Const_DataAccess::MREK_STATUS]) ? $data[Const_DataAccess::MREK_STATUS] : Module_ModuleManager_Main::RUN_MODULE_STATUS_FAILED; switch ($status) { case Module_ModuleManager_Main::RUN_MODULE_STATUS_FAILED: case Module_ModuleManager_Main::RUN_MODULE_STATUS_ABORT: case Module_ModuleManager_Main::RUN_MODULE_STATUS_SHUTDOWN: //case Module_ModuleManager_Main::RUN_MODULE_STATUS_TERM: $current_ap = Module_ControlCentre_ApManager::current_ap(); $mail_to = Module_ControlCentre_ApManager::interface_people(); if (!empty($mail_to)) { $mail_to = implode(';', $mail_to); $title = '接入任务[' . $task_id . ']'; $msg = '接入任务<span style="color:red;">[' . $task_id . ']</span>'; if (isset($current_ap[Module_AccessPoint_Main::FIELD_AP_NAME])) { $title .= $current_ap[Module_AccessPoint_Main::FIELD_AP_NAME]; $msg .= '<span style="font-size:2em;">'; $msg .= $current_ap[Module_AccessPoint_Main::FIELD_AP_NAME]; $msg .= '</span>'; } $title .= '<<' . Module_ModuleManager_Main::$run_module_status_list[$status] . '>>'; $msg .= '</span><span style="color:red;font-weight:bold;">' . Module_ModuleManager_Main::$run_module_status_list[$status] . '</span>'; isset($data[Const_DataAccess::MREK_DATA]['msg']) && ($msg .= '<p>原因如下:' . '<h2 style="color:red;">' . $data[Const_DataAccess::MREK_DATA]['msg'] . '</h2>' . '</p>'); Module_Notification_Mail::send_mail($mail_to, $title, $msg); } break; } } }