Exemple #1
0
 /**
  * @param array
  * @return array
  */
 static function process_result($result)
 {
     if ($result['errno'] !== 0) {
         Lib_Log::error("Redis: get result failed! result: %s", json_encode($result));
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_GET_CARD, 'get card failed! result:' . json_encode($result));
     }
     return Lib_Helper::get_return_struct($result['data']);
 }
Exemple #2
0
 /**
  * @return array
  */
 static function module_info()
 {
     $modules_info = new Model_ModulesInfo();
     $module_info = $modules_info->get_module_by_indentify(self::indentify());
     if ($module_info['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(__METHOD__ . ' faild! cause: ' . json_encode($module_info['data']));
         self::$module_id = self::MODULE_UNREG_ID;
         return Lib_Helper::get_err_struct(Const_Err_Db::ERR_GET_DATA_FAIL, '获取模块失败', __FILE__, __LINE__);
     }
     $module_info = $module_info['data'];
     if (empty($module_info)) {
         self::$module_id = self::MODULE_UNREG_ID;
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_MODULE_UNREG, '模块未注册', __FILE__, __LINE__);
     }
     self::$module_id = $module_info['_id'];
     return ['errno' => Const_Err_Base::ERR_OK, 'data' => $module_info];
 }
Exemple #3
0
 /**
  * @param int $task_id
  * @param int $mid
  * @return array|mixed
  */
 static function read_meta($task_id, $mid)
 {
     $mtrmr = new Model_TaskRunModuleRecord();
     $pre_result = $mtrmr->get_nearest_record_by_task_and_module($task_id, $mid, null, ['result']);
     if ($pre_result[Const_DataAccess::MREK_ERRNO] != Const_Err_Base::ERR_OK) {
         return $pre_result;
     }
     $pre_result = $pre_result[Const_DataAccess::MREK_DATA];
     if (!isset($pre_result['result']) || !isset($pre_result['result'][Const_DataAccess::MREK_ERRNO])) {
         return Lib_Helper::get_err_struct(Const_Err_Base::ERR_UNEXPECT_RETURN, 'there is no result to use: ' . json_encode($pre_result));
     }
     $meta = null;
     if ($pre_result['result'][Const_DataAccess::MREK_ERRNO] == Const_Err_Base::ERR_OK && isset($pre_result['result'][Const_DataAccess::MREK_DATA])) {
         $meta = $pre_result['result'][Const_DataAccess::MREK_DATA];
     } elseif (isset($pre_result['result'][Const_DataAccess::MREK_META])) {
         $meta = $pre_result['result'][Const_DataAccess::MREK_META];
     } else {
         return Lib_Helper::get_err_struct(Const_Err_Base::ERR_UNEXPECT_RETURN, 'there is no result to use: ' . json_encode($pre_result));
     }
     return Lib_Helper::get_return_struct($meta);
 }
Exemple #4
0
 /**
  * @param int $task_id
  * @param int $module_id
  * @param array $data
  * @param array $options
  * @return array
  */
 function run_module($task_id, $module_id, $data, $options)
 {
     $class = $this->get_module_class($module_id);
     Lib_Log::debug("%s begin run module [%d]\ttask_id:[%d]\toptions:%s", [__METHOD__, $module_id, $task_id, json_encode($options)]);
     $class->set_options($options);
     $this->run_hooks(self::get_run_module_hook_type(self::HOOK_TYPE_BEFORE_RUN_MODULE_PREFIX, $module_id), [$task_id, $module_id, $class, $data]);
     $this->run_hooks(self::HOOK_TYPE_BEFORE_RUN, [$task_id, $module_id, $class, $data]);
     try {
         $result = $class->run($task_id, $data);
     } catch (Exception $ex) {
         $code = $ex->getCode();
         $msg = $ex->getMessage();
         Lib_Log::error("Got a Exception, code [%d], message [%s]", [$code, $msg]);
         $result = Lib_Helper::get_err_struct($code, $msg);
     }
     $this->run_hooks(self::get_run_module_hook_type(self::HOOK_TYPE_AFTER_RUN_MODULE_PREFIX, $module_id), [$task_id, $module_id, $class, $result]);
     $this->run_hooks(self::HOOK_TYPE_AFTER_RUN, [$task_id, $module_id, $class, $result]);
     return $result;
 }
Exemple #5
0
 /**
  * @param int $module_id
  * @return array
  */
 static function functional_module_class_name($module_id)
 {
     $module = self::get_instance()->get_module_info_by_id($module_id);
     if (empty($module)) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_MODULE_NOT_EXISTS, '模块[' . $module_id . ']不存在');
     }
     if (!isset($module[Const_Module::META_TYPE])) {
         Lib_Log::error('errno:' . Const_Err_DataAccess::ERR_MODULE_INCORRECT_INFO . ' module not has meta type, module_id: ' . $module_id);
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_MODULE_INCORRECT_INFO, ' module not has meta type, module_id: ' . $module_id);
     }
     if (strcmp($module[Const_Module::META_TYPE], Const_Module::TYPE_FUNCTIONAL) !== 0) {
         Lib_Log::error('errno:' . Const_Err_DataAccess::ERR_MODULE_WRONG_TYPE . ' module is not functional module, module_id: ' . $module_id);
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_MODULE_WRONG_TYPE, ' module not has meta type, module_id: ' . $module_id);
     }
     $class_name = $module[Model_ModulesInfo::FIELD_MODULE_CLASS];
     if (!class_exists($class_name)) {
         Lib_Log::error("errno: %d, err: module class %s not exists!", [Const_Err_DataAccess::ERR_MODULE_CLASS_NOT_EXISTS, $class_name]);
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_MODULE_CLASS_NOT_EXISTS, 'Module class ' . $class_name . ' not exists!');
     }
     return Lib_Helper::get_return_struct($class_name);
 }
Exemple #6
0
 /**
  * @param int $ap_id
  * @param int $mode
  * @param array $options
  * @param string $php_script
  * @return array
  */
 static function exec_task_by_cli($ap_id, $mode = Module_FlowManager_Main::RUN_MODE_CALLBACK, $options = ['meta' => true], $php_script = 'tools/access_point.php')
 {
     $script = self::get_run_ap_script($ap_id, $mode, $options, $php_script);
     $result = 0;
     $output = null;
     exec($script, $output, $result);
     if ($result != 0) {
         Lib_Log::notice("run ap script failed. case: %s", $output);
         return Lib_Helper::get_err_struct($result, '执行失败');
     }
     return Lib_Helper::get_return_struct('运行成功');
 }
Exemple #7
0
 /**
  * @param array $counts
  * @return array
  */
 private function _incr_counts($counts)
 {
     if (!$this->_get_counter_status()) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_COUNTER_DISABLED, 'counter disabled');
     }
     $result = [];
     foreach ($counts as $_k => $_c) {
         $incr = $this->_incr($_k, $_c);
         if ($incr['errno'] != Const_Err_Base::ERR_OK) {
             continue;
         }
         $result[$_k] = $incr['data'];
     }
     return Lib_Helper::get_return_struct($result);
 }
Exemple #8
0
 /**
  * @param array $cond
  * @return array
  */
 public function get_tables($cond = [])
 {
     switch ($this->_driver) {
         case self::DB_DRIVER_MONGO:
         default:
             Lib_Log::debug(__METHOD__ . ': Use mongo driver, cond: %s', [json_encode($cond)]);
             try {
                 $result = $this->_db->GetTables($cond);
                 if (is_null($result)) {
                     $result = Lib_Helper::get_err_struct(Const_Err_Db::ERR_MONGO_COLLECTIONS_FAIL, '获取数据集失败', __FILE__, __LINE__);
                 } else {
                     $result = Lib_Helper::get_return_struct($result);
                 }
             } catch (Exception $ex) {
                 Lib_Log::error(__METHOD__ . " get faild! cond: %s, code: %d, messsage: %s", [json_encode($cond), $ex->getCode(), $ex->getMessage()]);
                 $result = Lib_Helper::get_err_struct(Const_Err_Db::ERR_MONGO_COLLECTIONS_FAIL, '获取数据集失败', __FILE__, __LINE__);
             }
     }
     return $result;
 }
Exemple #9
0
 /**
  * @param int $flow_id
  * @return array
  */
 private static function _get_fields_by_flow_id($flow_id)
 {
     $flow = new Module_FlowManager_Flow();
     $flow->id = $flow_id;
     $flow_info = $flow->get();
     if (!$flow_info) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_FLOW_NOT_EXISTS, 'no this flow, flow_id: ' . $flow_id);
     }
     $fields = Module_ModuleManager_InterfaceGen::get_instance()->gen_fields($flow);
     return Lib_Helper::get_return_struct($fields);
 }