@pisell/core 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +49 -0
|
@@ -0,0 +1,1119 @@
|
|
|
1
|
+
var _excluded = ["queueId", "module"];
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
15
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
16
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
17
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
19
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
+
import dayjs from "dayjs";
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
import { getUniqueId } from "@pisell/utils";
|
|
26
|
+
import useTasks from "./useTasks";
|
|
27
|
+
export var TasksManager = /*#__PURE__*/function () {
|
|
28
|
+
function TasksManager(app) {
|
|
29
|
+
var _this = this;
|
|
30
|
+
_classCallCheck(this, TasksManager);
|
|
31
|
+
_defineProperty(this, "taskFunctions", void 0);
|
|
32
|
+
_defineProperty(this, "tasks", {
|
|
33
|
+
// 内置模块, 定时任务专用
|
|
34
|
+
scheduledTasks: {}
|
|
35
|
+
});
|
|
36
|
+
_defineProperty(this, "app", void 0);
|
|
37
|
+
_defineProperty(this, "db", void 0);
|
|
38
|
+
_defineProperty(this, "useTasks", useTasks);
|
|
39
|
+
_defineProperty(this, "watchTaskCallback", function () {});
|
|
40
|
+
_defineProperty(this, "timerIds", []);
|
|
41
|
+
// 将任务队列状态同步到 local
|
|
42
|
+
_defineProperty(this, "saveTaskQueueToLocal", /*#__PURE__*/function () {
|
|
43
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(state) {
|
|
44
|
+
var _this$watchTaskCallba;
|
|
45
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
46
|
+
while (1) switch (_context.prev = _context.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
console.log("saveTaskQueueToLocal", state);
|
|
49
|
+
// let tasksData = await this.db.get<any>("tasks", "tasks");
|
|
50
|
+
// const newData = { id: "tasks", ...state };
|
|
51
|
+
// // 如果不存在则创建新文件
|
|
52
|
+
// if (!tasksData) {
|
|
53
|
+
// await this.db.add("tasks", newData);
|
|
54
|
+
// } else {
|
|
55
|
+
// await this.db.update("tasks", newData);
|
|
56
|
+
// }
|
|
57
|
+
(_this$watchTaskCallba = _this.watchTaskCallback) === null || _this$watchTaskCallba === void 0 || _this$watchTaskCallba.call(_this, _this.tasks);
|
|
58
|
+
case 2:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee);
|
|
63
|
+
}));
|
|
64
|
+
return function (_x) {
|
|
65
|
+
return _ref.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}());
|
|
68
|
+
// 从 local 加载任务队列状态
|
|
69
|
+
_defineProperty(this, "loadTaskQueueFromLocal", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
70
|
+
var tasks, module, queueId, _tasks$module, _iterator, _step, task;
|
|
71
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
72
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
_context2.prev = 0;
|
|
75
|
+
_context2.next = 3;
|
|
76
|
+
return _this.db.get("tasks", "tasks");
|
|
77
|
+
case 3:
|
|
78
|
+
tasks = _context2.sent;
|
|
79
|
+
// 卸载时清除一次性任务
|
|
80
|
+
for (module in tasks) {
|
|
81
|
+
for (queueId in tasks[module]) {
|
|
82
|
+
_iterator = _createForOfIteratorHelper((tasks === null || tasks === void 0 || (_tasks$module = tasks[module]) === null || _tasks$module === void 0 || (_tasks$module = _tasks$module[queueId]) === null || _tasks$module === void 0 ? void 0 : _tasks$module.tasks) || []);
|
|
83
|
+
try {
|
|
84
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
85
|
+
task = _step.value;
|
|
86
|
+
if (task.destroy) {
|
|
87
|
+
delete tasks[module][queueId].tasks;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
_iterator.e(err);
|
|
92
|
+
} finally {
|
|
93
|
+
_iterator.f();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return _context2.abrupt("return", tasks);
|
|
98
|
+
case 8:
|
|
99
|
+
_context2.prev = 8;
|
|
100
|
+
_context2.t0 = _context2["catch"](0);
|
|
101
|
+
console.log("loadTaskQueueFromLocal", _context2.t0);
|
|
102
|
+
return _context2.abrupt("return", null);
|
|
103
|
+
case 12:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context2.stop();
|
|
106
|
+
}
|
|
107
|
+
}, _callee2, null, [[0, 8]]);
|
|
108
|
+
})));
|
|
109
|
+
/**
|
|
110
|
+
* @title: 执行任务
|
|
111
|
+
* @description:
|
|
112
|
+
* @param {Task} task
|
|
113
|
+
* @return {*}
|
|
114
|
+
* @Author: zhiwei.Wang
|
|
115
|
+
* @Date: 2024-09-26 13:53
|
|
116
|
+
*/
|
|
117
|
+
_defineProperty(this, "runTask", /*#__PURE__*/function () {
|
|
118
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(task) {
|
|
119
|
+
var beforeAction, afterAction, action, beforeActionRes, afterActionRes, actionRes;
|
|
120
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
121
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
122
|
+
case 0:
|
|
123
|
+
// 执行任务前的钩子
|
|
124
|
+
beforeAction = _this.getTaskFunction(task.beforeAction || ""); // 执行任务后的钩子
|
|
125
|
+
afterAction = _this.getTaskFunction(task.afterAction || ""); // 当前任务
|
|
126
|
+
action = _this.getTaskFunction(task.action || "");
|
|
127
|
+
actionRes = {
|
|
128
|
+
status: "success"
|
|
129
|
+
};
|
|
130
|
+
_context3.prev = 4;
|
|
131
|
+
if (!beforeAction) {
|
|
132
|
+
_context3.next = 9;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
_context3.next = 8;
|
|
136
|
+
return beforeAction({
|
|
137
|
+
task: task
|
|
138
|
+
});
|
|
139
|
+
case 8:
|
|
140
|
+
beforeActionRes = _context3.sent;
|
|
141
|
+
case 9:
|
|
142
|
+
if (!action) {
|
|
143
|
+
_context3.next = 13;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
_context3.next = 12;
|
|
147
|
+
return action({
|
|
148
|
+
task: task,
|
|
149
|
+
beforeActionRes: beforeActionRes
|
|
150
|
+
});
|
|
151
|
+
case 12:
|
|
152
|
+
actionRes = _context3.sent;
|
|
153
|
+
case 13:
|
|
154
|
+
if (!afterAction) {
|
|
155
|
+
_context3.next = 17;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
_context3.next = 16;
|
|
159
|
+
return afterAction({
|
|
160
|
+
task: task,
|
|
161
|
+
actionRes: actionRes,
|
|
162
|
+
afterActionRes: afterActionRes
|
|
163
|
+
});
|
|
164
|
+
case 16:
|
|
165
|
+
afterActionRes = _context3.sent;
|
|
166
|
+
case 17:
|
|
167
|
+
_context3.next = 23;
|
|
168
|
+
break;
|
|
169
|
+
case 19:
|
|
170
|
+
_context3.prev = 19;
|
|
171
|
+
_context3.t0 = _context3["catch"](4);
|
|
172
|
+
_this.app.logger.addLog({
|
|
173
|
+
type: "info",
|
|
174
|
+
title: "\u4EFB\u52A1\u6267\u884C\u5931\u8D25-".concat(task.id),
|
|
175
|
+
metadata: {
|
|
176
|
+
error: _context3.t0,
|
|
177
|
+
taskPayload: task === null || task === void 0 ? void 0 : task.payload
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
actionRes = {
|
|
181
|
+
status: "failure"
|
|
182
|
+
};
|
|
183
|
+
case 23:
|
|
184
|
+
console.log("Tasks--->", "\u4EFB\u52A1\u6267\u884C\u6210\u529F: ".concat(task.id));
|
|
185
|
+
return _context3.abrupt("return", actionRes);
|
|
186
|
+
case 25:
|
|
187
|
+
case "end":
|
|
188
|
+
return _context3.stop();
|
|
189
|
+
}
|
|
190
|
+
}, _callee3, null, [[4, 19]]);
|
|
191
|
+
}));
|
|
192
|
+
return function (_x2) {
|
|
193
|
+
return _ref3.apply(this, arguments);
|
|
194
|
+
};
|
|
195
|
+
}());
|
|
196
|
+
/**
|
|
197
|
+
* @title: 清除任务定时器
|
|
198
|
+
*/
|
|
199
|
+
_defineProperty(this, "clearTaskTimer", function (params) {
|
|
200
|
+
var timerId = params.timerId,
|
|
201
|
+
taskId = params.taskId;
|
|
202
|
+
var _timerIds = [];
|
|
203
|
+
var needClearTimerIds = [];
|
|
204
|
+
_this.timerIds.forEach(function (id) {
|
|
205
|
+
var taskIdRult = taskId ? (id === null || id === void 0 ? void 0 : id.taskId) === taskId : true;
|
|
206
|
+
var timerIdRult = timerId ? (id === null || id === void 0 ? void 0 : id.timerId) === timerId : true;
|
|
207
|
+
if (taskIdRult && timerIdRult) {
|
|
208
|
+
needClearTimerIds.push(id);
|
|
209
|
+
} else {
|
|
210
|
+
_timerIds.push(id);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
if (needClearTimerIds.length) {
|
|
214
|
+
var _iterator2 = _createForOfIteratorHelper(needClearTimerIds),
|
|
215
|
+
_step2;
|
|
216
|
+
try {
|
|
217
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
218
|
+
var id = _step2.value;
|
|
219
|
+
clearTimeout(id.timerId);
|
|
220
|
+
}
|
|
221
|
+
} catch (err) {
|
|
222
|
+
_iterator2.e(err);
|
|
223
|
+
} finally {
|
|
224
|
+
_iterator2.f();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
_this.timerIds = _toConsumableArray(_timerIds || []);
|
|
228
|
+
});
|
|
229
|
+
/**
|
|
230
|
+
* @title: 计算下一次执行时间
|
|
231
|
+
* @description: 根据定时任务配置计算下一次执行时间
|
|
232
|
+
* @param {Task} task
|
|
233
|
+
* @return {string | null} 下一次执行时间
|
|
234
|
+
*/
|
|
235
|
+
_defineProperty(this, "calculateNextExecuteTime", function (task) {
|
|
236
|
+
if (!task.scheduled) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
var scheduled = task.scheduled,
|
|
240
|
+
scheduledResult = task.scheduledResult;
|
|
241
|
+
var now = dayjs();
|
|
242
|
+
|
|
243
|
+
// 如果有结束时间,检查是否已超过
|
|
244
|
+
if (scheduled.endAt && now.isAfter(dayjs(scheduled.endAt))) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// 如果 executeAt 是数组,找到第一个未来的时间点
|
|
249
|
+
if (Array.isArray(scheduled.executeAt)) {
|
|
250
|
+
var futureTime = scheduled.executeAt.map(function (time) {
|
|
251
|
+
return dayjs(time);
|
|
252
|
+
}).filter(function (time) {
|
|
253
|
+
return time.isAfter(now);
|
|
254
|
+
}).sort(function (a, b) {
|
|
255
|
+
return a.valueOf() - b.valueOf();
|
|
256
|
+
})[0];
|
|
257
|
+
if (futureTime) {
|
|
258
|
+
return futureTime.format("YYYY-MM-DD HH:mm:ss");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 如果所有时间点都已过,且设置了重复
|
|
262
|
+
if (!scheduled.repeat) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 如果是重复任务,计算下一次执行时间
|
|
268
|
+
if (scheduled.repeat && scheduledResult !== null && scheduledResult !== void 0 && scheduledResult.nextExecuteTime) {
|
|
269
|
+
var lastExecuteTime = dayjs(scheduledResult.nextExecuteTime);
|
|
270
|
+
var interval = scheduled.repeatInterval || 1;
|
|
271
|
+
var nextTime = lastExecuteTime;
|
|
272
|
+
switch (scheduled.repeatType) {
|
|
273
|
+
case 'daily':
|
|
274
|
+
nextTime = lastExecuteTime.add(interval, 'day');
|
|
275
|
+
break;
|
|
276
|
+
case 'weekly':
|
|
277
|
+
nextTime = lastExecuteTime.add(interval, 'week');
|
|
278
|
+
break;
|
|
279
|
+
case 'monthly':
|
|
280
|
+
nextTime = lastExecuteTime.add(interval, 'month');
|
|
281
|
+
break;
|
|
282
|
+
case 'yearly':
|
|
283
|
+
nextTime = lastExecuteTime.add(interval, 'year');
|
|
284
|
+
break;
|
|
285
|
+
default:
|
|
286
|
+
nextTime = lastExecuteTime.add(interval, 'day');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// 检查是否超过结束时间
|
|
290
|
+
if (scheduled.endAt && nextTime.isAfter(dayjs(scheduled.endAt))) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
return nextTime.format("YYYY-MM-DD HH:mm:ss");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 首次执行,返回 executeAt 指定的时间
|
|
297
|
+
var executeTime = Array.isArray(scheduled.executeAt) ? scheduled.executeAt[0] : scheduled.executeAt;
|
|
298
|
+
return dayjs(executeTime).format("YYYY-MM-DD HH:mm:ss");
|
|
299
|
+
});
|
|
300
|
+
/**
|
|
301
|
+
* @title: 启动定时任务
|
|
302
|
+
* @description: 在特定时间点执行任务(仅在 scheduledTasks 模块中生效)
|
|
303
|
+
* @param {Task} task
|
|
304
|
+
* @return {*}
|
|
305
|
+
*/
|
|
306
|
+
_defineProperty(this, "startScheduledTask", function (task) {
|
|
307
|
+
if (!task.scheduled) {
|
|
308
|
+
console.log("Tasks--->", "不是定时任务");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 安全检查:确保任务属于 scheduledTasks 模块
|
|
313
|
+
if (task.module !== 'scheduledTasks') {
|
|
314
|
+
console.warn("Tasks--->", "\u5B9A\u65F6\u4EFB\u52A1\u53EA\u5728 scheduledTasks \u6A21\u5757\u4E2D\u751F\u6548\uFF0C\u4EFB\u52A1 ".concat(task.id, " \u5C06\u4F5C\u4E3A\u666E\u901A\u4EFB\u52A1\u6267\u884C"));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
var nextExecuteTime = _this.calculateNextExecuteTime(task);
|
|
318
|
+
if (!nextExecuteTime) {
|
|
319
|
+
console.log("Tasks--->", "定时任务已完成或无下次执行时间", task);
|
|
320
|
+
// 删除已完成的定时任务
|
|
321
|
+
_this.deleteTask({
|
|
322
|
+
module: task.module,
|
|
323
|
+
queueId: task.queueId,
|
|
324
|
+
taskId: task.id
|
|
325
|
+
});
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
var now = dayjs();
|
|
329
|
+
var executeTime = dayjs(nextExecuteTime);
|
|
330
|
+
var delay = executeTime.diff(now);
|
|
331
|
+
if (delay < 0) {
|
|
332
|
+
console.log("Tasks--->", "执行时间已过,跳过此次执行");
|
|
333
|
+
// 如果是重复任务,计算下一次执行时间
|
|
334
|
+
if (task.scheduled.repeat) {
|
|
335
|
+
var _task$scheduledResult;
|
|
336
|
+
var _task = _objectSpread({}, task);
|
|
337
|
+
_task.scheduledResult = {
|
|
338
|
+
count: ((_task$scheduledResult = _task.scheduledResult) === null || _task$scheduledResult === void 0 ? void 0 : _task$scheduledResult.count) || 0,
|
|
339
|
+
nextExecuteTime: nextExecuteTime
|
|
340
|
+
};
|
|
341
|
+
var newTask = _this.updateTask({
|
|
342
|
+
module: task.module,
|
|
343
|
+
queueId: task.queueId,
|
|
344
|
+
taskId: task.id,
|
|
345
|
+
other: _task
|
|
346
|
+
});
|
|
347
|
+
if (newTask) {
|
|
348
|
+
_this.startScheduledTask(newTask);
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
_this.deleteTask({
|
|
352
|
+
module: task.module,
|
|
353
|
+
queueId: task.queueId,
|
|
354
|
+
taskId: task.id
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
console.log("Tasks--->", "\u5B9A\u65F6\u4EFB\u52A1\u5C06\u5728 ".concat(nextExecuteTime, " \u6267\u884C (").concat(delay, "ms \u540E)"), task);
|
|
360
|
+
|
|
361
|
+
// 创建定时器
|
|
362
|
+
var timerId = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
363
|
+
var _task2$scheduledResul, _task$scheduled, _task2, _newTask;
|
|
364
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
365
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
366
|
+
case 0:
|
|
367
|
+
_context4.prev = 0;
|
|
368
|
+
_context4.next = 3;
|
|
369
|
+
return _this.runTask(task);
|
|
370
|
+
case 3:
|
|
371
|
+
console.log("Tasks--->", "定时任务执行完成", task);
|
|
372
|
+
_task2 = _objectSpread({}, task);
|
|
373
|
+
_task2.scheduledResult = {
|
|
374
|
+
count: (((_task2$scheduledResul = _task2.scheduledResult) === null || _task2$scheduledResul === void 0 ? void 0 : _task2$scheduledResul.count) || 0) + 1,
|
|
375
|
+
timerId: timerId,
|
|
376
|
+
nextExecuteTime: nextExecuteTime
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// 如果是重复任务,继续调度下一次执行
|
|
380
|
+
if ((_task$scheduled = task.scheduled) !== null && _task$scheduled !== void 0 && _task$scheduled.repeat) {
|
|
381
|
+
_newTask = _this.updateTask({
|
|
382
|
+
module: task.module,
|
|
383
|
+
queueId: task.queueId,
|
|
384
|
+
taskId: task.id,
|
|
385
|
+
other: _task2
|
|
386
|
+
});
|
|
387
|
+
if (_newTask) {
|
|
388
|
+
_this.startScheduledTask(_newTask);
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
// 一次性任务执行完成后删除
|
|
392
|
+
_this.deleteTask({
|
|
393
|
+
module: task.module,
|
|
394
|
+
queueId: task.queueId,
|
|
395
|
+
taskId: task.id
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
_context4.next = 13;
|
|
399
|
+
break;
|
|
400
|
+
case 9:
|
|
401
|
+
_context4.prev = 9;
|
|
402
|
+
_context4.t0 = _context4["catch"](0);
|
|
403
|
+
_this.clearTaskTimer({
|
|
404
|
+
timerId: timerId
|
|
405
|
+
});
|
|
406
|
+
console.error("定时任务执行异常", _context4.t0);
|
|
407
|
+
case 13:
|
|
408
|
+
case "end":
|
|
409
|
+
return _context4.stop();
|
|
410
|
+
}
|
|
411
|
+
}, _callee4, null, [[0, 9]]);
|
|
412
|
+
})), delay);
|
|
413
|
+
_this.timerIds.push({
|
|
414
|
+
taskId: task.id,
|
|
415
|
+
timerId: timerId
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
/**
|
|
419
|
+
* @title: 启动轮询
|
|
420
|
+
* @description: 根据轮询间隔定期执行任务
|
|
421
|
+
* @param {Task} task
|
|
422
|
+
* @return {*}
|
|
423
|
+
*/
|
|
424
|
+
_defineProperty(this, "startPolling", function (task) {
|
|
425
|
+
if (!task.polling || !task.polling.interval) {
|
|
426
|
+
console.log("不是轮询任务");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 创建轮询定时器
|
|
431
|
+
var timerId = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
432
|
+
var _task$pollingResult, _task, newTask;
|
|
433
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
434
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
435
|
+
case 0:
|
|
436
|
+
_context5.prev = 0;
|
|
437
|
+
_context5.next = 3;
|
|
438
|
+
return _this.runTask(task);
|
|
439
|
+
case 3:
|
|
440
|
+
console.log("轮询任务", task);
|
|
441
|
+
_task = _objectSpread({}, task);
|
|
442
|
+
_task.pollingResult = {
|
|
443
|
+
count: (((_task$pollingResult = _task.pollingResult) === null || _task$pollingResult === void 0 ? void 0 : _task$pollingResult.count) || 0) + 1,
|
|
444
|
+
timerId: timerId
|
|
445
|
+
};
|
|
446
|
+
newTask = _this.updateTask({
|
|
447
|
+
module: task.module,
|
|
448
|
+
queueId: task.queueId,
|
|
449
|
+
taskId: task.id,
|
|
450
|
+
other: _task
|
|
451
|
+
});
|
|
452
|
+
if (newTask) {
|
|
453
|
+
_context5.next = 9;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
return _context5.abrupt("return");
|
|
457
|
+
case 9:
|
|
458
|
+
_this.startPolling(newTask);
|
|
459
|
+
_context5.next = 16;
|
|
460
|
+
break;
|
|
461
|
+
case 12:
|
|
462
|
+
_context5.prev = 12;
|
|
463
|
+
_context5.t0 = _context5["catch"](0);
|
|
464
|
+
_this.clearTaskTimer({
|
|
465
|
+
timerId: timerId
|
|
466
|
+
});
|
|
467
|
+
console.error("轮询任务异常", _context5.t0);
|
|
468
|
+
case 16:
|
|
469
|
+
case "end":
|
|
470
|
+
return _context5.stop();
|
|
471
|
+
}
|
|
472
|
+
}, _callee5, null, [[0, 12]]);
|
|
473
|
+
})), task.polling.interval);
|
|
474
|
+
_this.timerIds.push({
|
|
475
|
+
taskId: task.id,
|
|
476
|
+
timerId: timerId
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
/**
|
|
480
|
+
* @title: 创建任务数据
|
|
481
|
+
* @description:
|
|
482
|
+
* @param {Partial} payload
|
|
483
|
+
* @return {*}
|
|
484
|
+
* @Author: zhiwei.Wang
|
|
485
|
+
* @Date: 2024-09-26 13:54
|
|
486
|
+
*/
|
|
487
|
+
_defineProperty(this, "createTaskData", function (payload) {
|
|
488
|
+
return _objectSpread({
|
|
489
|
+
id: getUniqueId("task_"),
|
|
490
|
+
create_at: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
491
|
+
type: "local",
|
|
492
|
+
retries: 0,
|
|
493
|
+
maxRetries: 3,
|
|
494
|
+
status: "pending",
|
|
495
|
+
// 执行函数
|
|
496
|
+
action: "",
|
|
497
|
+
// 执行参数
|
|
498
|
+
payload: {},
|
|
499
|
+
// 执行前的钩子
|
|
500
|
+
beforeAction: "",
|
|
501
|
+
// 执行前的参数
|
|
502
|
+
beforePayload: {},
|
|
503
|
+
// 执行后的钩子
|
|
504
|
+
afterAction: "",
|
|
505
|
+
// 执行后的参数
|
|
506
|
+
afterPayload: {},
|
|
507
|
+
destroy: true
|
|
508
|
+
}, payload);
|
|
509
|
+
});
|
|
510
|
+
_defineProperty(this, "getTaskQueue", function (payload) {
|
|
511
|
+
var _this$tasks$module;
|
|
512
|
+
var queueId = payload.queueId,
|
|
513
|
+
module = payload.module;
|
|
514
|
+
return (_this$tasks$module = _this.tasks[module]) === null || _this$tasks$module === void 0 || (_this$tasks$module = _this$tasks$module[queueId]) === null || _this$tasks$module === void 0 ? void 0 : _this$tasks$module.tasks;
|
|
515
|
+
});
|
|
516
|
+
_defineProperty(this, "timeout", function (ms) {
|
|
517
|
+
return new Promise(function (resolve) {
|
|
518
|
+
setTimeout(function () {
|
|
519
|
+
resolve(true);
|
|
520
|
+
}, ms || 5000);
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
if (!app) {
|
|
524
|
+
throw new Error("app is required");
|
|
525
|
+
}
|
|
526
|
+
this.app = app;
|
|
527
|
+
this.taskFunctions = new Map();
|
|
528
|
+
this.tasks = {
|
|
529
|
+
scheduledTasks: {}
|
|
530
|
+
};
|
|
531
|
+
this.db = app.dbManager;
|
|
532
|
+
this.timerIds = [];
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// 单例模式
|
|
536
|
+
_createClass(TasksManager, [{
|
|
537
|
+
key: "addTaskFunction",
|
|
538
|
+
value:
|
|
539
|
+
// 注册任务函数
|
|
540
|
+
function addTaskFunction(name, fun) {
|
|
541
|
+
this.taskFunctions.set(name, fun);
|
|
542
|
+
console.log("Tasks--->", "\u6CE8\u518C\u4EFB\u52A1\u51FD\u6570\u6210\u529F: ".concat(name));
|
|
543
|
+
}
|
|
544
|
+
// 注册任务函数列表
|
|
545
|
+
}, {
|
|
546
|
+
key: "addTaskFunctions",
|
|
547
|
+
value: function addTaskFunctions(tasks) {
|
|
548
|
+
var _this2 = this;
|
|
549
|
+
tasks.forEach(function (_ref6) {
|
|
550
|
+
var name = _ref6.name,
|
|
551
|
+
fun = _ref6.fun;
|
|
552
|
+
_this2.taskFunctions.set(name, fun);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}, {
|
|
556
|
+
key: "getTasks",
|
|
557
|
+
value: function getTasks() {
|
|
558
|
+
return this.tasks;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// 获取任务函数
|
|
562
|
+
}, {
|
|
563
|
+
key: "getTaskFunction",
|
|
564
|
+
value: function getTaskFunction(name) {
|
|
565
|
+
if (!name) {
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
return this.taskFunctions.get(name);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 初始化任务
|
|
572
|
+
}, {
|
|
573
|
+
key: "init",
|
|
574
|
+
value: function () {
|
|
575
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
576
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
577
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
578
|
+
case 0:
|
|
579
|
+
case "end":
|
|
580
|
+
return _context6.stop();
|
|
581
|
+
}
|
|
582
|
+
}, _callee6);
|
|
583
|
+
}));
|
|
584
|
+
function init() {
|
|
585
|
+
return _init.apply(this, arguments);
|
|
586
|
+
}
|
|
587
|
+
return init;
|
|
588
|
+
}()
|
|
589
|
+
}, {
|
|
590
|
+
key: "run",
|
|
591
|
+
value: (
|
|
592
|
+
/**
|
|
593
|
+
* @title: 执行任务队列
|
|
594
|
+
* @description:
|
|
595
|
+
* @return {*}
|
|
596
|
+
* @Author: zhiwei.Wang
|
|
597
|
+
* @Date: 2024-09-26 13:52
|
|
598
|
+
*/
|
|
599
|
+
function () {
|
|
600
|
+
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(payload) {
|
|
601
|
+
var _this$tasks$module2;
|
|
602
|
+
var queueId, module, callback, currentQueue, _currentQueue$progres, _currentQueue$progres2, taskQueueStatus, taskQueue, errorTaskIds, _this$getTaskQueue, tasksToExecute, _iterator3, _step3, task, _yield$this$runTask, status, _task$pollingResult2, _other;
|
|
603
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
604
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
605
|
+
case 0:
|
|
606
|
+
queueId = payload.queueId, module = payload.module, callback = payload.callback; // 检查任务队列是否正在执行
|
|
607
|
+
currentQueue = (_this$tasks$module2 = this.tasks[module]) === null || _this$tasks$module2 === void 0 ? void 0 : _this$tasks$module2[queueId];
|
|
608
|
+
if (!(currentQueue !== null && currentQueue !== void 0 && currentQueue.isRunning)) {
|
|
609
|
+
_context7.next = 5;
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
console.warn("Tasks--->", "\u4EFB\u52A1\u961F\u5217 [".concat(module, "/").concat(queueId, "] \u6B63\u5728\u6267\u884C\u4E2D\uFF0C\u5DF2\u62E6\u622A\u91CD\u590D\u8C03\u7528\u3002"), "\u5F53\u524D\u8FDB\u5EA6: ".concat(((_currentQueue$progres = currentQueue.progress) === null || _currentQueue$progres === void 0 ? void 0 : _currentQueue$progres.completed) || 0, "/").concat(((_currentQueue$progres2 = currentQueue.progress) === null || _currentQueue$progres2 === void 0 ? void 0 : _currentQueue$progres2.total) || 0), "\u5982\u9700\u91CD\u65B0\u6267\u884C\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u4EFB\u52A1\u961F\u5217\u6267\u884C\u5B8C\u6210\u3002");
|
|
613
|
+
return _context7.abrupt("return");
|
|
614
|
+
case 5:
|
|
615
|
+
// 标记队列为执行中
|
|
616
|
+
this.updateQueueRunningState({
|
|
617
|
+
module: module,
|
|
618
|
+
queueId: queueId,
|
|
619
|
+
isRunning: true,
|
|
620
|
+
lastRunAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
|
621
|
+
});
|
|
622
|
+
console.log("Tasks--->", "\u4EFB\u52A1\u961F\u5217 [".concat(module, "/").concat(queueId, "] \u5F00\u59CB\u6267\u884C"));
|
|
623
|
+
|
|
624
|
+
//@ts-ignore 当前任务队列
|
|
625
|
+
taskQueueStatus = "";
|
|
626
|
+
_context7.prev = 8;
|
|
627
|
+
case 9:
|
|
628
|
+
if (!(taskQueueStatus !== "completed")) {
|
|
629
|
+
_context7.next = 72;
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
taskQueue = this.getTaskQueue(payload);
|
|
633
|
+
errorTaskIds = [];
|
|
634
|
+
if (!(taskQueue && taskQueue.length)) {
|
|
635
|
+
_context7.next = 62;
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
// 只执行未执行(pending)或失败(failure)的任务
|
|
639
|
+
tasksToExecute = taskQueue.filter(function (task) {
|
|
640
|
+
return (task === null || task === void 0 ? void 0 : task.status) === "pending" || (task === null || task === void 0 ? void 0 : task.status) === "failure";
|
|
641
|
+
});
|
|
642
|
+
console.log("Tasks--->", "需要执行的任务", tasksToExecute);
|
|
643
|
+
_iterator3 = _createForOfIteratorHelper(tasksToExecute);
|
|
644
|
+
_context7.prev = 16;
|
|
645
|
+
_iterator3.s();
|
|
646
|
+
case 18:
|
|
647
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
648
|
+
_context7.next = 49;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
task = _step3.value;
|
|
652
|
+
_context7.prev = 20;
|
|
653
|
+
if (!(task.retries !== undefined && task.maxRetries !== undefined && task.retries < task.maxRetries)) {
|
|
654
|
+
_context7.next = 40;
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
// 标记任务为执行中
|
|
658
|
+
task.status = "in-progress";
|
|
659
|
+
this.updateTask({
|
|
660
|
+
module: module,
|
|
661
|
+
queueId: queueId,
|
|
662
|
+
taskId: task.id,
|
|
663
|
+
other: {
|
|
664
|
+
status: task.status
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
// 定时任务(仅在 scheduledTasks 模块中生效)
|
|
669
|
+
if (!(task.scheduled && module === 'scheduledTasks')) {
|
|
670
|
+
_context7.next = 28;
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
this.startScheduledTask(task);
|
|
674
|
+
_context7.next = 37;
|
|
675
|
+
break;
|
|
676
|
+
case 28:
|
|
677
|
+
if (!task.polling) {
|
|
678
|
+
_context7.next = 32;
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
this.startPolling(task);
|
|
682
|
+
_context7.next = 37;
|
|
683
|
+
break;
|
|
684
|
+
case 32:
|
|
685
|
+
_context7.next = 34;
|
|
686
|
+
return this.runTask(task);
|
|
687
|
+
case 34:
|
|
688
|
+
_yield$this$runTask = _context7.sent;
|
|
689
|
+
status = _yield$this$runTask.status;
|
|
690
|
+
// 标记任务状态
|
|
691
|
+
task.status = status;
|
|
692
|
+
case 37:
|
|
693
|
+
// 成功: 删除任务
|
|
694
|
+
if (task.status === "success") {
|
|
695
|
+
if ((_task$pollingResult2 = task.pollingResult) !== null && _task$pollingResult2 !== void 0 && _task$pollingResult2.timerId) {}
|
|
696
|
+
this.deleteTask({
|
|
697
|
+
module: module,
|
|
698
|
+
queueId: queueId,
|
|
699
|
+
taskId: task.id
|
|
700
|
+
});
|
|
701
|
+
} else {
|
|
702
|
+
_other = {
|
|
703
|
+
status: task.status
|
|
704
|
+
}; // 失败: 标记任务为失败,并增加重试次数
|
|
705
|
+
if (task.status === "failure") {
|
|
706
|
+
_other.retries = task.retries + 1;
|
|
707
|
+
}
|
|
708
|
+
errorTaskIds.push(task.id);
|
|
709
|
+
this.updateTask({
|
|
710
|
+
module: module,
|
|
711
|
+
queueId: queueId,
|
|
712
|
+
taskId: task.id,
|
|
713
|
+
other: _other
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
_context7.next = 42;
|
|
717
|
+
break;
|
|
718
|
+
case 40:
|
|
719
|
+
console.log("Tasks--->", "任务没有重试次数,需要删除", task);
|
|
720
|
+
// 如果任务没有重试次数,则删除任务
|
|
721
|
+
this.deleteTask({
|
|
722
|
+
module: module,
|
|
723
|
+
queueId: queueId,
|
|
724
|
+
taskId: task.id
|
|
725
|
+
});
|
|
726
|
+
case 42:
|
|
727
|
+
_context7.next = 47;
|
|
728
|
+
break;
|
|
729
|
+
case 44:
|
|
730
|
+
_context7.prev = 44;
|
|
731
|
+
_context7.t0 = _context7["catch"](20);
|
|
732
|
+
console.error("任务异常", _context7.t0);
|
|
733
|
+
case 47:
|
|
734
|
+
_context7.next = 18;
|
|
735
|
+
break;
|
|
736
|
+
case 49:
|
|
737
|
+
_context7.next = 54;
|
|
738
|
+
break;
|
|
739
|
+
case 51:
|
|
740
|
+
_context7.prev = 51;
|
|
741
|
+
_context7.t1 = _context7["catch"](16);
|
|
742
|
+
_iterator3.e(_context7.t1);
|
|
743
|
+
case 54:
|
|
744
|
+
_context7.prev = 54;
|
|
745
|
+
_iterator3.f();
|
|
746
|
+
return _context7.finish(54);
|
|
747
|
+
case 57:
|
|
748
|
+
taskQueueStatus = (_this$getTaskQueue = this.getTaskQueue(payload)) !== null && _this$getTaskQueue !== void 0 && _this$getTaskQueue.some(function (task) {
|
|
749
|
+
return task.status === "failure";
|
|
750
|
+
}) ? "uncompleted" : "completed";
|
|
751
|
+
this.updateQueueStatus({
|
|
752
|
+
queueId: queueId,
|
|
753
|
+
module: module,
|
|
754
|
+
status: taskQueueStatus
|
|
755
|
+
});
|
|
756
|
+
console.log("Tasks--->", "任务队列执行完成", taskQueue);
|
|
757
|
+
_context7.next = 63;
|
|
758
|
+
break;
|
|
759
|
+
case 62:
|
|
760
|
+
taskQueueStatus = "completed";
|
|
761
|
+
case 63:
|
|
762
|
+
if (!(taskQueueStatus === "uncompleted")) {
|
|
763
|
+
_context7.next = 69;
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
this.app.logger.addLog({
|
|
767
|
+
type: "info",
|
|
768
|
+
title: "\u4EFB\u52A1\u961F\u5217\u6267\u884C\u5B58\u5728\u5931\u8D25-".concat(queueId),
|
|
769
|
+
metadata: {
|
|
770
|
+
taskQueue: taskQueue,
|
|
771
|
+
errorTaskIds: errorTaskIds
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
_context7.next = 67;
|
|
775
|
+
return this.timeout();
|
|
776
|
+
case 67:
|
|
777
|
+
_context7.next = 70;
|
|
778
|
+
break;
|
|
779
|
+
case 69:
|
|
780
|
+
if (taskQueueStatus === "completed") {
|
|
781
|
+
console.log("Tasks--->", "任务队列全部执行完成");
|
|
782
|
+
callback === null || callback === void 0 || callback();
|
|
783
|
+
}
|
|
784
|
+
case 70:
|
|
785
|
+
_context7.next = 9;
|
|
786
|
+
break;
|
|
787
|
+
case 72:
|
|
788
|
+
_context7.prev = 72;
|
|
789
|
+
// 无论成功还是失败,都要解除队列的执行状态
|
|
790
|
+
this.updateQueueRunningState({
|
|
791
|
+
module: module,
|
|
792
|
+
queueId: queueId,
|
|
793
|
+
isRunning: false
|
|
794
|
+
});
|
|
795
|
+
console.log("Tasks--->", "\u4EFB\u52A1\u961F\u5217 [".concat(module, "/").concat(queueId, "] \u6267\u884C\u7ED3\u675F"));
|
|
796
|
+
return _context7.finish(72);
|
|
797
|
+
case 76:
|
|
798
|
+
case "end":
|
|
799
|
+
return _context7.stop();
|
|
800
|
+
}
|
|
801
|
+
}, _callee7, this, [[8,, 72, 76], [16, 51, 54, 57], [20, 44]]);
|
|
802
|
+
}));
|
|
803
|
+
function run(_x3) {
|
|
804
|
+
return _run.apply(this, arguments);
|
|
805
|
+
}
|
|
806
|
+
return run;
|
|
807
|
+
}())
|
|
808
|
+
}, {
|
|
809
|
+
key: "deleteTask",
|
|
810
|
+
value: function deleteTask(payload) {
|
|
811
|
+
var _this$tasks,
|
|
812
|
+
_this3 = this;
|
|
813
|
+
var queueId = payload.queueId,
|
|
814
|
+
module = payload.module,
|
|
815
|
+
taskId = payload.taskId;
|
|
816
|
+
this.tasks[module][queueId].tasks = (_this$tasks = this.tasks) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks[module]) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks[queueId]) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks.tasks) === null || _this$tasks === void 0 ? void 0 : _this$tasks.filter(function (task) {
|
|
817
|
+
if (task.id === taskId) {
|
|
818
|
+
var _task$pollingResult3, _task$scheduledResult2;
|
|
819
|
+
// 清除轮询任务定时器
|
|
820
|
+
if ((_task$pollingResult3 = task.pollingResult) !== null && _task$pollingResult3 !== void 0 && _task$pollingResult3.timerId) {
|
|
821
|
+
_this3.clearTaskTimer({
|
|
822
|
+
timerId: task.pollingResult.timerId
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
// 清除定时任务定时器
|
|
826
|
+
if ((_task$scheduledResult2 = task.scheduledResult) !== null && _task$scheduledResult2 !== void 0 && _task$scheduledResult2.timerId) {
|
|
827
|
+
_this3.clearTaskTimer({
|
|
828
|
+
timerId: task.scheduledResult.timerId
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
return true;
|
|
834
|
+
});
|
|
835
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
836
|
+
console.log("Tasks--->", "删除指定任务", queueId, module, taskId);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* @title: 重试任务
|
|
841
|
+
* @description:
|
|
842
|
+
* @return {*}
|
|
843
|
+
* @Author: zhiwei.Wang
|
|
844
|
+
* @Date: 2024-09-26 13:53
|
|
845
|
+
*/
|
|
846
|
+
}, {
|
|
847
|
+
key: "retryTask",
|
|
848
|
+
value: function retryTask(payload) {
|
|
849
|
+
var queueId = payload.queueId,
|
|
850
|
+
module = payload.module;
|
|
851
|
+
this.run({
|
|
852
|
+
queueId: queueId,
|
|
853
|
+
module: module
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// 添加任务
|
|
858
|
+
}, {
|
|
859
|
+
key: "addTask",
|
|
860
|
+
value: function addTask(payload) {
|
|
861
|
+
var _this$tasks$module3,
|
|
862
|
+
_tasks$map,
|
|
863
|
+
_this4 = this;
|
|
864
|
+
var queueId = payload.queueId,
|
|
865
|
+
module = payload.module,
|
|
866
|
+
tasks = payload.tasks;
|
|
867
|
+
|
|
868
|
+
// 当前任务队列
|
|
869
|
+
var taskQueue = (_this$tasks$module3 = this.tasks[module]) === null || _this$tasks$module3 === void 0 || (_this$tasks$module3 = _this$tasks$module3[queueId]) === null || _this$tasks$module3 === void 0 ? void 0 : _this$tasks$module3.tasks;
|
|
870
|
+
var _tasks = _toConsumableArray(taskQueue || []);
|
|
871
|
+
|
|
872
|
+
// 创建新任务
|
|
873
|
+
var newTasks = tasks === null || tasks === void 0 || (_tasks$map = tasks.map) === null || _tasks$map === void 0 ? void 0 : _tasks$map.call(tasks, function (d) {
|
|
874
|
+
// 检查定时任务配置
|
|
875
|
+
if (d.scheduled && module !== 'scheduledTasks') {
|
|
876
|
+
console.warn("Tasks--->", "\u68C0\u6D4B\u5230\u5B9A\u65F6\u4EFB\u52A1\u914D\u7F6E\uFF0C\u4F46\u6A21\u5757\u4E3A \"".concat(module, "\"\u3002\u5B9A\u65F6\u4EFB\u52A1\u529F\u80FD\u4EC5\u5728 \"scheduledTasks\" \u6A21\u5757\u4E2D\u751F\u6548\u3002"), "\u8BE5\u4EFB\u52A1\u5C06\u4F5C\u4E3A\u666E\u901A\u4EFB\u52A1\u7ACB\u5373\u6267\u884C\u3002\u5982\u9700\u4F7F\u7528\u5B9A\u65F6\u529F\u80FD\uFF0C\u8BF7\u5C06\u4EFB\u52A1\u6DFB\u52A0\u5230 \"scheduledTasks\" \u6A21\u5757\u3002");
|
|
877
|
+
}
|
|
878
|
+
return _this4.createTaskData(_objectSpread(_objectSpread({}, d), {}, {
|
|
879
|
+
queueId: queueId,
|
|
880
|
+
module: module
|
|
881
|
+
}));
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// 合并
|
|
885
|
+
_tasks = _tasks.concat(newTasks);
|
|
886
|
+
this.setTasks({
|
|
887
|
+
queueId: queueId,
|
|
888
|
+
module: module,
|
|
889
|
+
tasks: _tasks
|
|
890
|
+
});
|
|
891
|
+
console.log("Tasks--->", "\u4EFB\u52A1\u6DFB\u52A0\u6210\u529F", newTasks);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// 更新任务状态
|
|
895
|
+
}, {
|
|
896
|
+
key: "updateTask",
|
|
897
|
+
value: function updateTask(payload) {
|
|
898
|
+
var _this$tasks$module4, _this$tasks$module5;
|
|
899
|
+
var queueId = payload.queueId,
|
|
900
|
+
taskId = payload.taskId,
|
|
901
|
+
other = payload.other,
|
|
902
|
+
module = payload.module;
|
|
903
|
+
var newTask = null;
|
|
904
|
+
var taskQueue = ((_this$tasks$module4 = this.tasks[module]) === null || _this$tasks$module4 === void 0 || (_this$tasks$module4 = _this$tasks$module4[queueId]) === null || _this$tasks$module4 === void 0 ? void 0 : _this$tasks$module4.tasks) || [];
|
|
905
|
+
var updatedTasks = taskQueue.map(function (task) {
|
|
906
|
+
if (task.id === taskId) {
|
|
907
|
+
newTask = _objectSpread(_objectSpread({}, task), other); // 更新任务状态
|
|
908
|
+
return newTask;
|
|
909
|
+
}
|
|
910
|
+
return task;
|
|
911
|
+
});
|
|
912
|
+
var newState = _objectSpread(_objectSpread({}, this.tasks), {}, _defineProperty({}, module, _objectSpread(_objectSpread({}, this.tasks[module]), {}, _defineProperty({}, queueId, _objectSpread(_objectSpread({}, (_this$tasks$module5 = this.tasks[module]) === null || _this$tasks$module5 === void 0 ? void 0 : _this$tasks$module5[queueId]), {}, {
|
|
913
|
+
status: updatedTasks.some(function (task) {
|
|
914
|
+
return task.status === "failure";
|
|
915
|
+
}) ? "uncompleted" : "completed",
|
|
916
|
+
tasks: updatedTasks
|
|
917
|
+
})))));
|
|
918
|
+
|
|
919
|
+
// 保存任务队列到本地存储
|
|
920
|
+
this.saveTaskQueueToLocal(newState);
|
|
921
|
+
this.tasks = newState;
|
|
922
|
+
return newTask;
|
|
923
|
+
}
|
|
924
|
+
}, {
|
|
925
|
+
key: "updateQueueStatus",
|
|
926
|
+
value: function updateQueueStatus(payload) {
|
|
927
|
+
var queueId = payload.queueId,
|
|
928
|
+
status = payload.status,
|
|
929
|
+
module = payload.module;
|
|
930
|
+
this.setTasksData({
|
|
931
|
+
queueId: queueId,
|
|
932
|
+
module: module,
|
|
933
|
+
status: status
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* @title: 更新队列运行状态
|
|
939
|
+
* @description: 标记队列是否正在执行
|
|
940
|
+
*/
|
|
941
|
+
}, {
|
|
942
|
+
key: "updateQueueRunningState",
|
|
943
|
+
value: function updateQueueRunningState(payload) {
|
|
944
|
+
var queueId = payload.queueId,
|
|
945
|
+
module = payload.module,
|
|
946
|
+
isRunning = payload.isRunning,
|
|
947
|
+
lastRunAt = payload.lastRunAt;
|
|
948
|
+
this.setTasksData({
|
|
949
|
+
queueId: queueId,
|
|
950
|
+
module: module,
|
|
951
|
+
isRunning: isRunning,
|
|
952
|
+
lastRunAt: lastRunAt
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// 设置任务
|
|
957
|
+
}, {
|
|
958
|
+
key: "setTasksData",
|
|
959
|
+
value: function setTasksData(payload) {
|
|
960
|
+
var queueId = payload.queueId,
|
|
961
|
+
module = payload.module,
|
|
962
|
+
data = _objectWithoutProperties(payload, _excluded);
|
|
963
|
+
var moduleData = this.tasks[module] || {};
|
|
964
|
+
var queueIdData = moduleData[queueId] || {};
|
|
965
|
+
var newState = _objectSpread(_objectSpread({}, this.tasks), {}, _defineProperty({}, module, _objectSpread(_objectSpread({}, moduleData), {}, _defineProperty({}, queueId, _objectSpread(_objectSpread({}, queueIdData), data)))));
|
|
966
|
+
|
|
967
|
+
// 保存任务队列到本地存储
|
|
968
|
+
this.saveTaskQueueToLocal(newState);
|
|
969
|
+
this.tasks = newState;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// 设置任务
|
|
973
|
+
}, {
|
|
974
|
+
key: "setTasks",
|
|
975
|
+
value: function setTasks(payload) {
|
|
976
|
+
var queueId = payload.queueId,
|
|
977
|
+
module = payload.module,
|
|
978
|
+
tasks = payload.tasks;
|
|
979
|
+
this.setTasksData({
|
|
980
|
+
queueId: queueId,
|
|
981
|
+
module: module,
|
|
982
|
+
tasks: tasks
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
}, {
|
|
986
|
+
key: "clearAllTaskTimer",
|
|
987
|
+
value: function clearAllTaskTimer(tasks) {
|
|
988
|
+
var _iterator4 = _createForOfIteratorHelper(tasks || []),
|
|
989
|
+
_step4;
|
|
990
|
+
try {
|
|
991
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
992
|
+
var task = _step4.value;
|
|
993
|
+
this.clearTaskTimer({
|
|
994
|
+
taskId: task.id
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
} catch (err) {
|
|
998
|
+
_iterator4.e(err);
|
|
999
|
+
} finally {
|
|
1000
|
+
_iterator4.f();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// 清空任务
|
|
1005
|
+
}, {
|
|
1006
|
+
key: "clearTasks",
|
|
1007
|
+
value: function clearTasks(payload) {
|
|
1008
|
+
var _this$tasks2;
|
|
1009
|
+
var queueId = payload.queueId,
|
|
1010
|
+
module = payload.module;
|
|
1011
|
+
if (!((_this$tasks2 = this.tasks) !== null && _this$tasks2 !== void 0 && (_this$tasks2 = _this$tasks2[module]) !== null && _this$tasks2 !== void 0 && _this$tasks2[queueId])) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
this.clearAllTaskTimer(this.tasks[module][queueId].tasks);
|
|
1015
|
+
this.tasks[module][queueId].tasks = [];
|
|
1016
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
1017
|
+
console.log("Tasks--->", "清空指定任务", queueId, module);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// 清空全部任务
|
|
1021
|
+
}, {
|
|
1022
|
+
key: "clearAllTasks",
|
|
1023
|
+
value: function clearAllTasks() {
|
|
1024
|
+
this.tasks = {};
|
|
1025
|
+
this.saveTaskQueueToLocal(this.tasks);
|
|
1026
|
+
if (this.timerIds.length) {
|
|
1027
|
+
var _iterator5 = _createForOfIteratorHelper(this.timerIds),
|
|
1028
|
+
_step5;
|
|
1029
|
+
try {
|
|
1030
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1031
|
+
var timerId = _step5.value;
|
|
1032
|
+
clearTimeout(timerId);
|
|
1033
|
+
}
|
|
1034
|
+
} catch (err) {
|
|
1035
|
+
_iterator5.e(err);
|
|
1036
|
+
} finally {
|
|
1037
|
+
_iterator5.f();
|
|
1038
|
+
}
|
|
1039
|
+
this.timerIds = [];
|
|
1040
|
+
}
|
|
1041
|
+
console.log("Tasks--->", "清空全部任务");
|
|
1042
|
+
}
|
|
1043
|
+
}, {
|
|
1044
|
+
key: "watchTask",
|
|
1045
|
+
value: function watchTask(callback) {
|
|
1046
|
+
this.watchTaskCallback = callback;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* @title: 获取队列执行状态
|
|
1051
|
+
* @description: 获取指定队列的执行状态和进度信息
|
|
1052
|
+
* @param {string} module - 模块名
|
|
1053
|
+
* @param {string} queueId - 队列ID
|
|
1054
|
+
* @return {object} 队列状态信息
|
|
1055
|
+
*/
|
|
1056
|
+
}, {
|
|
1057
|
+
key: "getQueueStatus",
|
|
1058
|
+
value: function getQueueStatus(module, queueId) {
|
|
1059
|
+
var _this$tasks$module6, _queue$tasks;
|
|
1060
|
+
var queue = (_this$tasks$module6 = this.tasks[module]) === null || _this$tasks$module6 === void 0 ? void 0 : _this$tasks$module6[queueId];
|
|
1061
|
+
if (!queue) {
|
|
1062
|
+
return null;
|
|
1063
|
+
}
|
|
1064
|
+
return {
|
|
1065
|
+
isRunning: queue.isRunning || false,
|
|
1066
|
+
status: queue.status,
|
|
1067
|
+
progress: queue.progress || {
|
|
1068
|
+
total: 0,
|
|
1069
|
+
completed: 0,
|
|
1070
|
+
failed: 0,
|
|
1071
|
+
inProgress: 0
|
|
1072
|
+
},
|
|
1073
|
+
lastRunAt: queue.lastRunAt || null,
|
|
1074
|
+
tasksCount: ((_queue$tasks = queue.tasks) === null || _queue$tasks === void 0 ? void 0 : _queue$tasks.length) || 0
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* @title: 获取所有队列状态
|
|
1080
|
+
* @description: 获取所有任务队列的执行状态概览
|
|
1081
|
+
* @return {object} 所有队列的状态信息
|
|
1082
|
+
*/
|
|
1083
|
+
}, {
|
|
1084
|
+
key: "getAllQueuesStatus",
|
|
1085
|
+
value: function getAllQueuesStatus() {
|
|
1086
|
+
var result = {};
|
|
1087
|
+
for (var module in this.tasks) {
|
|
1088
|
+
result[module] = {};
|
|
1089
|
+
for (var queueId in this.tasks[module]) {
|
|
1090
|
+
var _queue$tasks2;
|
|
1091
|
+
var queue = this.tasks[module][queueId];
|
|
1092
|
+
result[module][queueId] = {
|
|
1093
|
+
isRunning: queue.isRunning || false,
|
|
1094
|
+
status: queue.status,
|
|
1095
|
+
progress: queue.progress || {
|
|
1096
|
+
total: 0,
|
|
1097
|
+
completed: 0,
|
|
1098
|
+
failed: 0,
|
|
1099
|
+
inProgress: 0
|
|
1100
|
+
},
|
|
1101
|
+
lastRunAt: queue.lastRunAt || null,
|
|
1102
|
+
tasksCount: ((_queue$tasks2 = queue.tasks) === null || _queue$tasks2 === void 0 ? void 0 : _queue$tasks2.length) || 0
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
}], [{
|
|
1109
|
+
key: "getInstance",
|
|
1110
|
+
value: function getInstance(app) {
|
|
1111
|
+
if (!TasksManager.instance && app) {
|
|
1112
|
+
TasksManager.instance = new TasksManager(app);
|
|
1113
|
+
}
|
|
1114
|
+
return TasksManager.instance;
|
|
1115
|
+
}
|
|
1116
|
+
}]);
|
|
1117
|
+
return TasksManager;
|
|
1118
|
+
}();
|
|
1119
|
+
_defineProperty(TasksManager, "instance", void 0);
|