ins_Task.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-04-07 17:38:12
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-04-08 17:33:06
  8. */
  9. #ifndef __INS_TASK_HPP_
  10. #define __INS_TASK_HPP_
  11. #include <iostream>
  12. #include <memory>
  13. #include "private/ins_module_private.hpp"
  14. using namespace std;
  15. namespace ins
  16. {
  17. // *Ins 任务类型
  18. enum class InsTaskType{
  19. INS_TASK_GET = 1 << 0,
  20. INS_TASK_POST = 1 << 1,
  21. INS_TASK_PUT = 1 << 2,
  22. INS_TASK_DELETE = 1 << 3,
  23. };
  24. // *Ins 任务Token
  25. enum class InsTaskToken{
  26. INS_TASK_INTERNAL_TOKEN = 1 << 0,
  27. INS_TASK_INCLIENT_TOKEN = 1 << 1,
  28. INS_TASK_NETTY_TOKEN = 1 << 1,
  29. INS_TASK_K8S_TOKEN = 1 << 2,
  30. };
  31. // *ins 任务Flag
  32. enum class InsTaskFlag{
  33. INS_TASK_ASYNC_FLAG = 1 << 0,
  34. INS_TASK_SYNC_FLAG = 1 << 1,
  35. };
  36. /**
  37. * @description:
  38. * @param {*}
  39. * @return {*}
  40. */
  41. class InsTask:public NonCopyable
  42. {
  43. public:
  44. using TaskPtr = std::shared_ptr<std::function<void()>>;
  45. using Ptr = std::shared_ptr<InsTask>;
  46. private:
  47. /**
  48. * @description: 创建
  49. * @param {InsTaskType} type
  50. * @param {InsTaskToken} token
  51. * @param {TaskPtr} task
  52. * @return {*}
  53. */
  54. InsTask(TaskPtr task, InsTaskType type, InsTaskToken token, InsTaskFlag flag):task_(task), type_(type), token_(token){
  55. CreateTime = this->getDataTime();
  56. UpdateTime = CreateTime;
  57. flag_ = flag;
  58. }
  59. public:
  60. ~InsTask(){}
  61. /**
  62. * @description: 创建新的实例
  63. * @param {TaskPtr} task 任务ptr
  64. * @param {InsTaskType} type 任务类型
  65. * @param {InsTaskToken} token 任务token
  66. * @param {InsTaskFlag} flag 任务flag 异步执行或者同步
  67. * 默认为 get、 内部、 异步执行
  68. * @return {*}
  69. */
  70. static std::shared_ptr<InsTask> CreateNew(TaskPtr task, InsTaskType type = InsTaskType::INS_TASK_GET, \
  71. InsTaskToken token = InsTaskToken::INS_TASK_INTERNAL_TOKEN, InsTaskFlag flag = InsTaskFlag::INS_TASK_ASYNC_FLAG);
  72. /**
  73. * @description: 创建TaskPtr
  74. * @param {function<void()>} t 任务
  75. * @return {*}
  76. */
  77. static TaskPtr MakeTaskPtr(std::function<void()> t);
  78. /**
  79. * @description: 获取任务
  80. * @param {*}
  81. * @return {*}
  82. */
  83. TaskPtr getTask();
  84. /**
  85. * @description: 获取Flag
  86. * @param {*}
  87. * @return {*}
  88. */
  89. InsTaskFlag getFlag();
  90. private:
  91. TaskPtr task_ = nullptr;
  92. InsTaskType type_;
  93. InsTaskToken token_;
  94. InsTaskFlag flag_;
  95. std::string CreateTime;
  96. std::string UpdateTime;
  97. };
  98. } // namespace ins
  99. #endif