123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-04-07 17:38:12
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-04-08 17:33:06
- */
- #ifndef __INS_TASK_HPP_
- #define __INS_TASK_HPP_
- #include <iostream>
- #include <memory>
- #include "private/ins_module_private.hpp"
- using namespace std;
- namespace ins
- {
- // *Ins 任务类型
- enum class InsTaskType{
- INS_TASK_GET = 1 << 0,
- INS_TASK_POST = 1 << 1,
- INS_TASK_PUT = 1 << 2,
- INS_TASK_DELETE = 1 << 3,
- };
- // *Ins 任务Token
- enum class InsTaskToken{
- INS_TASK_INTERNAL_TOKEN = 1 << 0,
- INS_TASK_INCLIENT_TOKEN = 1 << 1,
- INS_TASK_NETTY_TOKEN = 1 << 1,
- INS_TASK_K8S_TOKEN = 1 << 2,
- };
- // *ins 任务Flag
- enum class InsTaskFlag{
- INS_TASK_ASYNC_FLAG = 1 << 0,
- INS_TASK_SYNC_FLAG = 1 << 1,
- };
- /**
- * @description:
- * @param {*}
- * @return {*}
- */
- class InsTask:public NonCopyable
- {
- public:
- using TaskPtr = std::shared_ptr<std::function<void()>>;
- using Ptr = std::shared_ptr<InsTask>;
- private:
- /**
- * @description: 创建
- * @param {InsTaskType} type
- * @param {InsTaskToken} token
- * @param {TaskPtr} task
- * @return {*}
- */
- InsTask(TaskPtr task, InsTaskType type, InsTaskToken token, InsTaskFlag flag):task_(task), type_(type), token_(token){
- CreateTime = this->getDataTime();
- UpdateTime = CreateTime;
- flag_ = flag;
- }
- public:
- ~InsTask(){}
- /**
- * @description: 创建新的实例
- * @param {TaskPtr} task 任务ptr
- * @param {InsTaskType} type 任务类型
- * @param {InsTaskToken} token 任务token
- * @param {InsTaskFlag} flag 任务flag 异步执行或者同步
- * 默认为 get、 内部、 异步执行
- * @return {*}
- */
- static std::shared_ptr<InsTask> CreateNew(TaskPtr task, InsTaskType type = InsTaskType::INS_TASK_GET, \
- InsTaskToken token = InsTaskToken::INS_TASK_INTERNAL_TOKEN, InsTaskFlag flag = InsTaskFlag::INS_TASK_ASYNC_FLAG);
- /**
- * @description: 创建TaskPtr
- * @param {function<void()>} t 任务
- * @return {*}
- */
- static TaskPtr MakeTaskPtr(std::function<void()> t);
- /**
- * @description: 获取任务
- * @param {*}
- * @return {*}
- */
- TaskPtr getTask();
- /**
- * @description: 获取Flag
- * @param {*}
- * @return {*}
- */
- InsTaskFlag getFlag();
- private:
- TaskPtr task_ = nullptr;
- InsTaskType type_;
- InsTaskToken token_;
- InsTaskFlag flag_;
-
- std::string CreateTime;
- std::string UpdateTime;
- };
- } // namespace ins
- #endif
|