agora-foundation 1.0.0
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/lib/decorator/bound/index.d.ts +5 -0
- package/lib/decorator/bound/index.js +19 -0
- package/lib/decorator/index.d.ts +3 -0
- package/lib/decorator/index.js +33 -0
- package/lib/decorator/lodash/index.d.ts +16 -0
- package/lib/decorator/lodash/index.js +42 -0
- package/lib/decorator/log/handler.d.ts +4 -0
- package/lib/decorator/log/handler.js +63 -0
- package/lib/decorator/log/index.d.ts +4 -0
- package/lib/decorator/log/index.js +38 -0
- package/lib/decorator/log/log-serializer.d.ts +8 -0
- package/lib/decorator/log/log-serializer.js +67 -0
- package/lib/decorator/proxy.d.ts +9 -0
- package/lib/decorator/proxy.js +154 -0
- package/lib/decorator/type.d.ts +16 -0
- package/lib/decorator/type.js +12 -0
- package/lib/logger/constants.d.ts +11 -0
- package/lib/logger/constants.js +11 -0
- package/lib/logger/hijack.d.ts +4 -0
- package/lib/logger/hijack.js +65 -0
- package/lib/logger/index.d.ts +8 -0
- package/lib/logger/index.js +70 -0
- package/lib/logger/logger-impl.d.ts +19 -0
- package/lib/logger/logger-impl.js +111 -0
- package/lib/logger/manager-impl.d.ts +8 -0
- package/lib/logger/manager-impl.js +67 -0
- package/lib/logger/type.d.ts +25 -0
- package/lib/logger/type.js +14 -0
- package/lib/schedule/index.d.ts +3 -0
- package/lib/schedule/index.js +25 -0
- package/lib/schedule/scheduler.d.ts +21 -0
- package/lib/schedule/scheduler.js +108 -0
- package/lib/schedule/task.d.ts +36 -0
- package/lib/schedule/task.js +167 -0
- package/lib/upload/index.d.ts +2 -0
- package/lib/upload/index.js +13 -0
- package/lib/upload/scheduler.d.ts +15 -0
- package/lib/upload/scheduler.js +114 -0
- package/lib/upload/type.d.ts +11 -0
- package/lib/upload/type.js +6 -0
- package/lib/utilities/async-retry.d.ts +63 -0
- package/lib/utilities/async-retry.js +180 -0
- package/lib/utilities/env.d.ts +12 -0
- package/lib/utilities/env.js +56 -0
- package/lib/utilities/events.d.ts +13 -0
- package/lib/utilities/events.js +114 -0
- package/lib/utilities/file-reader.d.ts +1 -0
- package/lib/utilities/file-reader.js +22 -0
- package/lib/utilities/interceptor.d.ts +6 -0
- package/lib/utilities/interceptor.js +28 -0
- package/lib/utilities/misc.d.ts +5 -0
- package/lib/utilities/misc.js +52 -0
- package/lib/utilities/observable.d.ts +11 -0
- package/lib/utilities/observable.js +73 -0
- package/lib/utilities/race-condition.d.ts +1 -0
- package/lib/utilities/race-condition.js +24 -0
- package/lib/utilities/value-check.d.ts +1 -0
- package/lib/utilities/value-check.js +10 -0
- package/lib/utilities/zip.d.ts +1 -0
- package/lib/utilities/zip.js +107 -0
- package/lib/worker/constants.d.ts +11 -0
- package/lib/worker/constants.js +19 -0
- package/lib/worker/handler/binary.d.ts +5 -0
- package/lib/worker/handler/binary.js +161 -0
- package/lib/worker/handler/db.d.ts +21 -0
- package/lib/worker/handler/db.js +42 -0
- package/lib/worker/handler/fs-log.d.ts +3 -0
- package/lib/worker/handler/fs-log.js +156 -0
- package/lib/worker/handler/log.d.ts +12 -0
- package/lib/worker/handler/log.js +246 -0
- package/lib/worker/handler/reply.d.ts +3 -0
- package/lib/worker/handler/reply.js +22 -0
- package/lib/worker/index.d.ts +2 -0
- package/lib/worker/index.js +15 -0
- package/lib/worker/interactor.d.ts +25 -0
- package/lib/worker/interactor.js +378 -0
- package/lib/worker/mutex.d.ts +5 -0
- package/lib/worker/mutex.js +65 -0
- package/lib/worker/type.d.ts +1 -0
- package/lib/worker/type.js +6 -0
- package/lib/worker/worker-entry.d.ts +1 -0
- package/lib/worker/worker-entry.js +5 -0
- package/lib/worker/worker-factory.d.ts +1 -0
- package/lib/worker/worker-factory.js +14 -0
- package/lib/worker/worker-installer.d.ts +2 -0
- package/lib/worker/worker-installer.js +72 -0
- package/package.json +29 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "LogLevel", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _type.LogLevel;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.getLogger = exports.getLogManager = void 0;
|
|
14
|
+
Object.defineProperty(exports, "logLevelMap", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _constants.logLevelMap;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "restoreConsoleHijack", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _hijack.restoreConsoleHijack;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
exports.setLogLevel = void 0;
|
|
27
|
+
Object.defineProperty(exports, "setupConsoleHijack", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function get() {
|
|
30
|
+
return _hijack.setupConsoleHijack;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
require("core-js/modules/es.array.for-each.js");
|
|
34
|
+
require("core-js/modules/es.array.iterator.js");
|
|
35
|
+
require("core-js/modules/es.map.js");
|
|
36
|
+
require("core-js/modules/es.object.to-string.js");
|
|
37
|
+
require("core-js/modules/es.string.iterator.js");
|
|
38
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
39
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
40
|
+
var _worker = require("../worker");
|
|
41
|
+
var _loggerImpl = require("./logger-impl");
|
|
42
|
+
var _managerImpl = require("./manager-impl");
|
|
43
|
+
var _type = require("./type");
|
|
44
|
+
var _hijack = require("./hijack");
|
|
45
|
+
var _constants = require("./constants");
|
|
46
|
+
var loggerRegistrar = new Map();
|
|
47
|
+
var logLevel = _type.LogLevel.DEBUG;
|
|
48
|
+
var getLogger = exports.getLogger = function getLogger() {
|
|
49
|
+
var label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
|
|
50
|
+
if (!loggerRegistrar.has(label)) {
|
|
51
|
+
loggerRegistrar.set(label, new _loggerImpl.LoggerImpl(label, {
|
|
52
|
+
console: true,
|
|
53
|
+
database: true
|
|
54
|
+
}, logLevel, (0, _worker.getWorkerSingleton)()));
|
|
55
|
+
}
|
|
56
|
+
return loggerRegistrar.get(label);
|
|
57
|
+
};
|
|
58
|
+
var logManager;
|
|
59
|
+
var getLogManager = exports.getLogManager = function getLogManager() {
|
|
60
|
+
if (!logManager) {
|
|
61
|
+
logManager = new _managerImpl.LogManagerImpl((0, _worker.getWorkerSingleton)());
|
|
62
|
+
}
|
|
63
|
+
return logManager;
|
|
64
|
+
};
|
|
65
|
+
var setLogLevel = exports.setLogLevel = function setLogLevel(_logLevel) {
|
|
66
|
+
logLevel = _logLevel;
|
|
67
|
+
loggerRegistrar.forEach(function (logger) {
|
|
68
|
+
logger.setLogLevel(logLevel);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LogLevel, Logger, LogWorkerInteractor } from './type';
|
|
2
|
+
export declare class LoggerImpl implements Logger {
|
|
3
|
+
private _label;
|
|
4
|
+
private _dest;
|
|
5
|
+
private _logLevel;
|
|
6
|
+
private _logWorkerInteractor;
|
|
7
|
+
constructor(_label: string, _dest: {
|
|
8
|
+
console: boolean;
|
|
9
|
+
database: boolean;
|
|
10
|
+
}, _logLevel: LogLevel, _logWorkerInteractor: LogWorkerInteractor);
|
|
11
|
+
setLogLevel(logLevel: LogLevel): void;
|
|
12
|
+
debug(...args: unknown[]): void;
|
|
13
|
+
info(...args: unknown[]): void;
|
|
14
|
+
warn(...args: unknown[]): void;
|
|
15
|
+
error(...args: unknown[]): void;
|
|
16
|
+
private _log;
|
|
17
|
+
private _pipeToDatabase;
|
|
18
|
+
private _pipeToConsole;
|
|
19
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.LoggerImpl = void 0;
|
|
9
|
+
require("core-js/modules/es.array.concat.js");
|
|
10
|
+
require("core-js/modules/es.array.join.js");
|
|
11
|
+
require("core-js/modules/es.array.unshift.js");
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
var _upperCase = _interopRequireDefault(require("lodash/upperCase"));
|
|
16
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
17
|
+
var _constants = require("./constants");
|
|
18
|
+
var _type = require("./type");
|
|
19
|
+
var _hijack = require("./hijack");
|
|
20
|
+
var _padEnd = _interopRequireDefault(require("lodash/padEnd"));
|
|
21
|
+
var LoggerImpl = exports.LoggerImpl = /*#__PURE__*/function () {
|
|
22
|
+
function LoggerImpl(_label, _dest, _logLevel, _logWorkerInteractor) {
|
|
23
|
+
(0, _classCallCheck2["default"])(this, LoggerImpl);
|
|
24
|
+
this._label = _label;
|
|
25
|
+
this._dest = _dest;
|
|
26
|
+
this._logLevel = _logLevel;
|
|
27
|
+
this._logWorkerInteractor = _logWorkerInteractor;
|
|
28
|
+
}
|
|
29
|
+
return (0, _createClass2["default"])(LoggerImpl, [{
|
|
30
|
+
key: "setLogLevel",
|
|
31
|
+
value: function setLogLevel(logLevel) {
|
|
32
|
+
this._logLevel = logLevel;
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "debug",
|
|
36
|
+
value: function debug() {
|
|
37
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
38
|
+
args[_key] = arguments[_key];
|
|
39
|
+
}
|
|
40
|
+
this._log.apply(this, [_type.LogLevel.DEBUG].concat(args));
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "info",
|
|
44
|
+
value: function info() {
|
|
45
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
46
|
+
args[_key2] = arguments[_key2];
|
|
47
|
+
}
|
|
48
|
+
this._log.apply(this, [_type.LogLevel.INFO].concat(args));
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "warn",
|
|
52
|
+
value: function warn() {
|
|
53
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
54
|
+
args[_key3] = arguments[_key3];
|
|
55
|
+
}
|
|
56
|
+
this._log.apply(this, [_type.LogLevel.WARN].concat(args));
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "error",
|
|
60
|
+
value: function error() {
|
|
61
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
62
|
+
args[_key4] = arguments[_key4];
|
|
63
|
+
}
|
|
64
|
+
this._log.apply(this, [_type.LogLevel.ERROR].concat(args));
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "_log",
|
|
68
|
+
value: function _log(logLevel) {
|
|
69
|
+
if (logLevel > this._logLevel) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// prepend log level to second position of the log message
|
|
73
|
+
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
|
74
|
+
args[_key5 - 1] = arguments[_key5];
|
|
75
|
+
}
|
|
76
|
+
args.unshift((0, _padEnd["default"])((0, _upperCase["default"])(_constants.logLevelMap[logLevel] || 'unknown'), 5, ' '));
|
|
77
|
+
// prepend log level to first position of the log message
|
|
78
|
+
args.unshift((0, _dayjs["default"])().format('YYYY-MM-DD HH:mm:ss'));
|
|
79
|
+
if (this._dest.database) {
|
|
80
|
+
this._pipeToDatabase(args.join(' '));
|
|
81
|
+
}
|
|
82
|
+
if (this._dest.console) {
|
|
83
|
+
this._pipeToConsole(logLevel, args);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "_pipeToDatabase",
|
|
88
|
+
value: function _pipeToDatabase(message) {
|
|
89
|
+
this._logWorkerInteractor.sendLog(message, this._label);
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "_pipeToConsole",
|
|
93
|
+
value: function _pipeToConsole(logLevel, args) {
|
|
94
|
+
var console = _hijack.originConsole;
|
|
95
|
+
switch (logLevel) {
|
|
96
|
+
case _type.LogLevel.DEBUG:
|
|
97
|
+
console.debug.apply(console, (0, _toConsumableArray2["default"])(args));
|
|
98
|
+
break;
|
|
99
|
+
case _type.LogLevel.INFO:
|
|
100
|
+
console.info.apply(console, (0, _toConsumableArray2["default"])(args));
|
|
101
|
+
break;
|
|
102
|
+
case _type.LogLevel.WARN:
|
|
103
|
+
console.warn.apply(console, (0, _toConsumableArray2["default"])(args));
|
|
104
|
+
break;
|
|
105
|
+
case _type.LogLevel.ERROR:
|
|
106
|
+
console.error.apply(console, (0, _toConsumableArray2["default"])(args));
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}]);
|
|
111
|
+
}();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogManager, LogWorkerInteractor } from './type';
|
|
2
|
+
export declare class LogManagerImpl implements LogManager {
|
|
3
|
+
private _logWorkerInteractor;
|
|
4
|
+
private _lastId;
|
|
5
|
+
constructor(_logWorkerInteractor: LogWorkerInteractor);
|
|
6
|
+
flush(): Promise<void>;
|
|
7
|
+
collectLogs(): Promise<File>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.LogManagerImpl = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var LogManagerImpl = exports.LogManagerImpl = /*#__PURE__*/function () {
|
|
15
|
+
function LogManagerImpl(_logWorkerInteractor) {
|
|
16
|
+
(0, _classCallCheck2["default"])(this, LogManagerImpl);
|
|
17
|
+
(0, _defineProperty2["default"])(this, "_lastId", -1);
|
|
18
|
+
this._logWorkerInteractor = _logWorkerInteractor;
|
|
19
|
+
}
|
|
20
|
+
return (0, _createClass2["default"])(LogManagerImpl, [{
|
|
21
|
+
key: "flush",
|
|
22
|
+
value: function () {
|
|
23
|
+
var _flush = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
24
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
this._logWorkerInteractor.deleteLogs(['default'], this._lastId);
|
|
28
|
+
case 1:
|
|
29
|
+
case "end":
|
|
30
|
+
return _context.stop();
|
|
31
|
+
}
|
|
32
|
+
}, _callee, this);
|
|
33
|
+
}));
|
|
34
|
+
function flush() {
|
|
35
|
+
return _flush.apply(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
return flush;
|
|
38
|
+
}()
|
|
39
|
+
}, {
|
|
40
|
+
key: "collectLogs",
|
|
41
|
+
value: function () {
|
|
42
|
+
var _collectLogs = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
43
|
+
var _yield$this$_logWorke, file, lastId;
|
|
44
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
45
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
_context2.next = 2;
|
|
48
|
+
return this._logWorkerInteractor.collectLogs(['default']);
|
|
49
|
+
case 2:
|
|
50
|
+
_yield$this$_logWorke = _context2.sent;
|
|
51
|
+
file = _yield$this$_logWorke.file;
|
|
52
|
+
lastId = _yield$this$_logWorke.lastId;
|
|
53
|
+
this._lastId = lastId;
|
|
54
|
+
return _context2.abrupt("return", file);
|
|
55
|
+
case 7:
|
|
56
|
+
case "end":
|
|
57
|
+
return _context2.stop();
|
|
58
|
+
}
|
|
59
|
+
}, _callee2, this);
|
|
60
|
+
}));
|
|
61
|
+
function collectLogs() {
|
|
62
|
+
return _collectLogs.apply(this, arguments);
|
|
63
|
+
}
|
|
64
|
+
return collectLogs;
|
|
65
|
+
}()
|
|
66
|
+
}]);
|
|
67
|
+
}();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
ERROR = 1,
|
|
3
|
+
WARN = 2,
|
|
4
|
+
INFO = 3,
|
|
5
|
+
DEBUG = 4
|
|
6
|
+
}
|
|
7
|
+
export interface Logger {
|
|
8
|
+
debug: typeof console.debug;
|
|
9
|
+
info: typeof console.info;
|
|
10
|
+
warn: typeof console.warn;
|
|
11
|
+
error: typeof console.error;
|
|
12
|
+
}
|
|
13
|
+
export interface LogManager {
|
|
14
|
+
collectLogs(): Promise<File>;
|
|
15
|
+
flush(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface LogWorkerInteractor {
|
|
18
|
+
setMaxRecords(maxRecords: number): Promise<void>;
|
|
19
|
+
sendLog(message: string, label: string): void;
|
|
20
|
+
collectLogs(labels: string[]): Promise<{
|
|
21
|
+
file: File;
|
|
22
|
+
lastId: number;
|
|
23
|
+
}>;
|
|
24
|
+
deleteLogs(labels: string[], lastId: number): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LogLevel = void 0;
|
|
8
|
+
var LogLevel = exports.LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
9
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
10
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
11
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
12
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
13
|
+
return LogLevel;
|
|
14
|
+
}({});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.iterator.js");
|
|
4
|
+
require("core-js/modules/es.object.define-property.js");
|
|
5
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
6
|
+
require("core-js/modules/es.object.to-string.js");
|
|
7
|
+
require("core-js/modules/es.string.iterator.js");
|
|
8
|
+
require("core-js/modules/es.weak-map.js");
|
|
9
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
10
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
11
|
+
Object.defineProperty(exports, "__esModule", {
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "ActionWhenTaskFail", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _task.ActionWhenTaskFail;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.AgoraScheduler = void 0;
|
|
21
|
+
var _AgoraScheduler = _interopRequireWildcard(require("./scheduler"));
|
|
22
|
+
exports.AgoraScheduler = _AgoraScheduler;
|
|
23
|
+
var _task = require("./task");
|
|
24
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
25
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ActionWhenTaskFail } from '.';
|
|
2
|
+
export type Task = {
|
|
3
|
+
start: () => void;
|
|
4
|
+
stop: () => void;
|
|
5
|
+
isStopped: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare abstract class Duration {
|
|
8
|
+
private static _factors;
|
|
9
|
+
static second(amount: number): number;
|
|
10
|
+
static minute(amount: number): number;
|
|
11
|
+
static hour(amount: number): number;
|
|
12
|
+
}
|
|
13
|
+
declare class Scheduler {
|
|
14
|
+
private _tasks;
|
|
15
|
+
addPollingTask(runnable: () => void, intervalInMs: number, immediate?: boolean, onFail?: () => ActionWhenTaskFail): Task;
|
|
16
|
+
addDelayTask(runnable: () => void, delayInMs: number): Task;
|
|
17
|
+
addIntervalTask(runnable: () => void, intervalInMs: number, immediate?: boolean, onFail?: () => ActionWhenTaskFail): Task;
|
|
18
|
+
}
|
|
19
|
+
export declare const createScheduler: () => Scheduler;
|
|
20
|
+
export declare const shared: Scheduler;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.shared = exports.createScheduler = exports.Duration = void 0;
|
|
9
|
+
require("core-js/modules/es.array.iterator.js");
|
|
10
|
+
require("core-js/modules/es.object.to-string.js");
|
|
11
|
+
require("core-js/modules/es.string.iterator.js");
|
|
12
|
+
require("core-js/modules/es.weak-set.js");
|
|
13
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
14
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
var _ = require(".");
|
|
18
|
+
var _task = require("./task");
|
|
19
|
+
var Duration = exports.Duration = /*#__PURE__*/function () {
|
|
20
|
+
function Duration() {
|
|
21
|
+
(0, _classCallCheck2["default"])(this, Duration);
|
|
22
|
+
}
|
|
23
|
+
return (0, _createClass2["default"])(Duration, null, [{
|
|
24
|
+
key: "second",
|
|
25
|
+
value: function second(amount) {
|
|
26
|
+
return this._factors.second * amount;
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "minute",
|
|
30
|
+
value: function minute(amount) {
|
|
31
|
+
return this._factors.minute * amount;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "hour",
|
|
35
|
+
value: function hour(amount) {
|
|
36
|
+
return this._factors.hour * amount;
|
|
37
|
+
}
|
|
38
|
+
}]);
|
|
39
|
+
}();
|
|
40
|
+
(0, _defineProperty2["default"])(Duration, "_factors", {
|
|
41
|
+
hour: 1000 * 60 * 60,
|
|
42
|
+
minute: 1000 * 60,
|
|
43
|
+
second: 1000
|
|
44
|
+
});
|
|
45
|
+
var Scheduler = /*#__PURE__*/function () {
|
|
46
|
+
function Scheduler() {
|
|
47
|
+
(0, _classCallCheck2["default"])(this, Scheduler);
|
|
48
|
+
(0, _defineProperty2["default"])(this, "_tasks", new WeakSet());
|
|
49
|
+
}
|
|
50
|
+
return (0, _createClass2["default"])(Scheduler, [{
|
|
51
|
+
key: "addPollingTask",
|
|
52
|
+
value: function addPollingTask(runnable, intervalInMs) {
|
|
53
|
+
var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
54
|
+
var onFail = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
|
|
55
|
+
return _.ActionWhenTaskFail.CONTINUE;
|
|
56
|
+
};
|
|
57
|
+
var task = new _task.PollingTask({
|
|
58
|
+
runnable: runnable,
|
|
59
|
+
interval: intervalInMs,
|
|
60
|
+
immediate: immediate,
|
|
61
|
+
onFail: onFail
|
|
62
|
+
});
|
|
63
|
+
task.start();
|
|
64
|
+
this._tasks.add(task);
|
|
65
|
+
return task;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "addDelayTask",
|
|
69
|
+
value: function addDelayTask(runnable, delayInMs) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
var task = new _task.PollingTask({
|
|
72
|
+
runnable: runnable,
|
|
73
|
+
interval: delayInMs,
|
|
74
|
+
once: true,
|
|
75
|
+
onFail: function onFail() {
|
|
76
|
+
return _.ActionWhenTaskFail.EXIT;
|
|
77
|
+
},
|
|
78
|
+
onComplete: function onComplete() {
|
|
79
|
+
_this._tasks["delete"](task);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
task.start();
|
|
83
|
+
this._tasks.add(task);
|
|
84
|
+
return task;
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "addIntervalTask",
|
|
88
|
+
value: function addIntervalTask(runnable, intervalInMs) {
|
|
89
|
+
var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
90
|
+
var onFail = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
|
|
91
|
+
return _.ActionWhenTaskFail.CONTINUE;
|
|
92
|
+
};
|
|
93
|
+
var task = new _task.IntervalTask({
|
|
94
|
+
runnable: runnable,
|
|
95
|
+
interval: intervalInMs,
|
|
96
|
+
immediate: immediate,
|
|
97
|
+
onFail: onFail
|
|
98
|
+
});
|
|
99
|
+
task.start();
|
|
100
|
+
this._tasks.add(task);
|
|
101
|
+
return task;
|
|
102
|
+
}
|
|
103
|
+
}]);
|
|
104
|
+
}();
|
|
105
|
+
var createScheduler = exports.createScheduler = function createScheduler() {
|
|
106
|
+
return new Scheduler();
|
|
107
|
+
};
|
|
108
|
+
var shared = exports.shared = createScheduler();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare enum ActionWhenTaskFail {
|
|
2
|
+
CONTINUE = 0,
|
|
3
|
+
EXIT = 1
|
|
4
|
+
}
|
|
5
|
+
type AnyFunction = () => void;
|
|
6
|
+
type IntervalArguments = {
|
|
7
|
+
runnable: AnyFunction;
|
|
8
|
+
interval: number;
|
|
9
|
+
immediate?: boolean;
|
|
10
|
+
onFail: (err: any) => ActionWhenTaskFail;
|
|
11
|
+
onComplete?: () => void;
|
|
12
|
+
};
|
|
13
|
+
type PollingArguments = IntervalArguments & {
|
|
14
|
+
once?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare class PollingTask {
|
|
17
|
+
private __arguments;
|
|
18
|
+
private __timer?;
|
|
19
|
+
private __running;
|
|
20
|
+
constructor(__arguments: PollingArguments);
|
|
21
|
+
start(): void;
|
|
22
|
+
private poll;
|
|
23
|
+
stop(): void;
|
|
24
|
+
get isStopped(): boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class IntervalTask {
|
|
27
|
+
private __arguments;
|
|
28
|
+
private __timer?;
|
|
29
|
+
private __running;
|
|
30
|
+
constructor(__arguments: IntervalArguments);
|
|
31
|
+
start(): void;
|
|
32
|
+
private poll;
|
|
33
|
+
stop(): void;
|
|
34
|
+
get isStopped(): boolean;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.object.define-property.js");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PollingTask = exports.IntervalTask = exports.ActionWhenTaskFail = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
|
+
require("core-js/modules/es.error.cause.js");
|
|
15
|
+
require("core-js/modules/es.error.to-string.js");
|
|
16
|
+
require("core-js/modules/es.object.to-string.js");
|
|
17
|
+
require("core-js/modules/es.promise.js");
|
|
18
|
+
require("core-js/modules/web.timers.js");
|
|
19
|
+
var ActionWhenTaskFail = exports.ActionWhenTaskFail = /*#__PURE__*/function (ActionWhenTaskFail) {
|
|
20
|
+
ActionWhenTaskFail[ActionWhenTaskFail["CONTINUE"] = 0] = "CONTINUE";
|
|
21
|
+
ActionWhenTaskFail[ActionWhenTaskFail["EXIT"] = 1] = "EXIT";
|
|
22
|
+
return ActionWhenTaskFail;
|
|
23
|
+
}({});
|
|
24
|
+
var promisify = function promisify(runnable) {
|
|
25
|
+
return new Promise( /*#__PURE__*/function () {
|
|
26
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve, reject) {
|
|
27
|
+
var v;
|
|
28
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
_context.prev = 0;
|
|
32
|
+
_context.next = 3;
|
|
33
|
+
return runnable();
|
|
34
|
+
case 3:
|
|
35
|
+
v = _context.sent;
|
|
36
|
+
resolve(v);
|
|
37
|
+
_context.next = 10;
|
|
38
|
+
break;
|
|
39
|
+
case 7:
|
|
40
|
+
_context.prev = 7;
|
|
41
|
+
_context.t0 = _context["catch"](0);
|
|
42
|
+
reject(_context.t0);
|
|
43
|
+
case 10:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}, _callee, null, [[0, 7]]);
|
|
48
|
+
}));
|
|
49
|
+
return function (_x, _x2) {
|
|
50
|
+
return _ref.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
}());
|
|
53
|
+
};
|
|
54
|
+
var PollingTask = exports.PollingTask = /*#__PURE__*/function () {
|
|
55
|
+
function PollingTask(__arguments) {
|
|
56
|
+
(0, _classCallCheck2["default"])(this, PollingTask);
|
|
57
|
+
(0, _defineProperty2["default"])(this, "__running", false);
|
|
58
|
+
this.__arguments = __arguments;
|
|
59
|
+
}
|
|
60
|
+
return (0, _createClass2["default"])(PollingTask, [{
|
|
61
|
+
key: "start",
|
|
62
|
+
value: function start() {
|
|
63
|
+
var _this = this;
|
|
64
|
+
if (this.__running) {
|
|
65
|
+
throw new Error('Task is already running');
|
|
66
|
+
}
|
|
67
|
+
this.__running = true;
|
|
68
|
+
if (this.__arguments.immediate) {
|
|
69
|
+
promisify(this.__arguments.runnable).then(function () {
|
|
70
|
+
_this.poll();
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
this.poll();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: "poll",
|
|
78
|
+
value: function poll() {
|
|
79
|
+
var _this2 = this;
|
|
80
|
+
if (!this.__running) {
|
|
81
|
+
return this.stop();
|
|
82
|
+
}
|
|
83
|
+
this.__timer = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
84
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
85
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
_context2.next = 2;
|
|
88
|
+
return promisify(_this2.__arguments.runnable)["catch"](function (err) {
|
|
89
|
+
var action = _this2.__arguments.onFail(err);
|
|
90
|
+
if (action === ActionWhenTaskFail.EXIT) {
|
|
91
|
+
_this2.__running = false;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
case 2:
|
|
95
|
+
!_this2.__arguments.once && _this2.poll();
|
|
96
|
+
case 3:
|
|
97
|
+
case "end":
|
|
98
|
+
return _context2.stop();
|
|
99
|
+
}
|
|
100
|
+
}, _callee2);
|
|
101
|
+
})), this.__arguments.interval);
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "stop",
|
|
105
|
+
value: function stop() {
|
|
106
|
+
clearTimeout(this.__timer);
|
|
107
|
+
this.__running = false;
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "isStopped",
|
|
111
|
+
get: function get() {
|
|
112
|
+
return !this.__running;
|
|
113
|
+
}
|
|
114
|
+
}]);
|
|
115
|
+
}();
|
|
116
|
+
var IntervalTask = exports.IntervalTask = /*#__PURE__*/function () {
|
|
117
|
+
function IntervalTask(__arguments) {
|
|
118
|
+
(0, _classCallCheck2["default"])(this, IntervalTask);
|
|
119
|
+
(0, _defineProperty2["default"])(this, "__running", false);
|
|
120
|
+
this.__arguments = __arguments;
|
|
121
|
+
}
|
|
122
|
+
return (0, _createClass2["default"])(IntervalTask, [{
|
|
123
|
+
key: "start",
|
|
124
|
+
value: function start() {
|
|
125
|
+
var _this3 = this;
|
|
126
|
+
if (this.__running) {
|
|
127
|
+
throw new Error('Task is already running');
|
|
128
|
+
}
|
|
129
|
+
this.__running = true;
|
|
130
|
+
var _this$__arguments = this.__arguments,
|
|
131
|
+
immediate = _this$__arguments.immediate,
|
|
132
|
+
interval = _this$__arguments.interval;
|
|
133
|
+
if (immediate) {
|
|
134
|
+
this.poll();
|
|
135
|
+
}
|
|
136
|
+
this.__timer = setInterval(function () {
|
|
137
|
+
_this3.poll();
|
|
138
|
+
}, interval);
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "poll",
|
|
142
|
+
value: function poll() {
|
|
143
|
+
var _this4 = this;
|
|
144
|
+
if (!this.__running) {
|
|
145
|
+
return this.stop();
|
|
146
|
+
}
|
|
147
|
+
var runnable = this.__arguments.runnable;
|
|
148
|
+
promisify(runnable)["catch"](function (err) {
|
|
149
|
+
var action = _this4.__arguments.onFail(err);
|
|
150
|
+
if (action === ActionWhenTaskFail.EXIT) {
|
|
151
|
+
_this4.__running = false;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "stop",
|
|
157
|
+
value: function stop() {
|
|
158
|
+
clearInterval(this.__timer);
|
|
159
|
+
this.__running = false;
|
|
160
|
+
}
|
|
161
|
+
}, {
|
|
162
|
+
key: "isStopped",
|
|
163
|
+
get: function get() {
|
|
164
|
+
return !this.__running;
|
|
165
|
+
}
|
|
166
|
+
}]);
|
|
167
|
+
}();
|