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,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.symbol.js");
|
|
4
|
+
require("core-js/modules/es.symbol.description.js");
|
|
5
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
6
|
+
require("core-js/modules/es.error.cause.js");
|
|
7
|
+
require("core-js/modules/es.error.to-string.js");
|
|
8
|
+
require("core-js/modules/es.array.from.js");
|
|
9
|
+
require("core-js/modules/es.array.is-array.js");
|
|
10
|
+
require("core-js/modules/es.array.iterator.js");
|
|
11
|
+
require("core-js/modules/es.array.slice.js");
|
|
12
|
+
require("core-js/modules/es.date.to-string.js");
|
|
13
|
+
require("core-js/modules/es.function.name.js");
|
|
14
|
+
require("core-js/modules/es.object.define-property.js");
|
|
15
|
+
require("core-js/modules/es.object.to-string.js");
|
|
16
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
17
|
+
require("core-js/modules/es.regexp.test.js");
|
|
18
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
19
|
+
require("core-js/modules/es.string.iterator.js");
|
|
20
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
21
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
exports.collectLogsOnFs = exports.clearTempLogs = void 0;
|
|
26
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
27
|
+
require("core-js/modules/es.array.concat.js");
|
|
28
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
29
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
|
30
|
+
var _constants = require("../constants");
|
|
31
|
+
var _db = require("./db");
|
|
32
|
+
var _reply = require("./reply");
|
|
33
|
+
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; } } }; }
|
|
34
|
+
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); }
|
|
35
|
+
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; }
|
|
36
|
+
var collectLogsOnFs = exports.collectLogsOnFs = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(self, callId, logDirPath) {
|
|
38
|
+
var fs;
|
|
39
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
40
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
try {
|
|
43
|
+
fs = window.require("fs");
|
|
44
|
+
fs.readdir(logDirPath, /*#__PURE__*/function () {
|
|
45
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(err, files) {
|
|
46
|
+
var zip, _iterator, _step, file, filePath, logsStr, blob, buffer;
|
|
47
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
if (!err) {
|
|
51
|
+
_context.next = 5;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
console.error("[logger] failed to read log dir.", err);
|
|
55
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.COLLECT_LOGS_ON_FS, {
|
|
56
|
+
isSuccess: false
|
|
57
|
+
});
|
|
58
|
+
_context.next = 19;
|
|
59
|
+
break;
|
|
60
|
+
case 5:
|
|
61
|
+
if (!(files.length === 0)) {
|
|
62
|
+
_context.next = 9;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.COLLECT_LOGS_ON_FS, {
|
|
66
|
+
isSuccess: true,
|
|
67
|
+
buffer: null
|
|
68
|
+
});
|
|
69
|
+
_context.next = 19;
|
|
70
|
+
break;
|
|
71
|
+
case 9:
|
|
72
|
+
zip = new _jszip["default"]();
|
|
73
|
+
_iterator = _createForOfIteratorHelper(files);
|
|
74
|
+
try {
|
|
75
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
76
|
+
file = _step.value;
|
|
77
|
+
filePath = "".concat(logDirPath, "/").concat(file);
|
|
78
|
+
logsStr = fs.readFileSync(filePath, "utf8");
|
|
79
|
+
zip.file(file, logsStr);
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_iterator.e(err);
|
|
83
|
+
} finally {
|
|
84
|
+
_iterator.f();
|
|
85
|
+
}
|
|
86
|
+
_context.next = 14;
|
|
87
|
+
return zip.generateAsync({
|
|
88
|
+
type: "blob"
|
|
89
|
+
});
|
|
90
|
+
case 14:
|
|
91
|
+
blob = _context.sent;
|
|
92
|
+
_context.next = 17;
|
|
93
|
+
return blob.arrayBuffer();
|
|
94
|
+
case 17:
|
|
95
|
+
buffer = _context.sent;
|
|
96
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.COLLECT_LOGS_ON_FS, {
|
|
97
|
+
isSuccess: true,
|
|
98
|
+
buffer: buffer
|
|
99
|
+
});
|
|
100
|
+
case 19:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee);
|
|
105
|
+
}));
|
|
106
|
+
return function (_x4, _x5) {
|
|
107
|
+
return _ref2.apply(this, arguments);
|
|
108
|
+
};
|
|
109
|
+
}());
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error("[logger] failed to get buffer.", e);
|
|
112
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.GET_BUFFER, {
|
|
113
|
+
isSuccess: false
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
case 1:
|
|
117
|
+
case "end":
|
|
118
|
+
return _context2.stop();
|
|
119
|
+
}
|
|
120
|
+
}, _callee2);
|
|
121
|
+
}));
|
|
122
|
+
return function collectLogsOnFs(_x, _x2, _x3) {
|
|
123
|
+
return _ref.apply(this, arguments);
|
|
124
|
+
};
|
|
125
|
+
}();
|
|
126
|
+
var clearTempLogs = exports.clearTempLogs = /*#__PURE__*/function () {
|
|
127
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(self, callId) {
|
|
128
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
129
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
130
|
+
case 0:
|
|
131
|
+
_context3.prev = 0;
|
|
132
|
+
_context3.next = 3;
|
|
133
|
+
return _db.db.tempLogs.clear();
|
|
134
|
+
case 3:
|
|
135
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.CLEAR_TEMP_LOGS, {
|
|
136
|
+
isSuccess: true
|
|
137
|
+
});
|
|
138
|
+
_context3.next = 10;
|
|
139
|
+
break;
|
|
140
|
+
case 6:
|
|
141
|
+
_context3.prev = 6;
|
|
142
|
+
_context3.t0 = _context3["catch"](0);
|
|
143
|
+
console.error("[logger] failed to clear temp logs.", _context3.t0);
|
|
144
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.CLEAR_TEMP_LOGS, {
|
|
145
|
+
isSuccess: false
|
|
146
|
+
});
|
|
147
|
+
case 10:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context3.stop();
|
|
150
|
+
}
|
|
151
|
+
}, _callee3, null, [[0, 6]]);
|
|
152
|
+
}));
|
|
153
|
+
return function clearTempLogs(_x6, _x7) {
|
|
154
|
+
return _ref3.apply(this, arguments);
|
|
155
|
+
};
|
|
156
|
+
}();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WorkerContext } from '../type';
|
|
2
|
+
type Log = {
|
|
3
|
+
content: string;
|
|
4
|
+
label: string;
|
|
5
|
+
created_at: number;
|
|
6
|
+
timestamp: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const writeLog: (self: WorkerContext, callId: number, log: Log) => void;
|
|
9
|
+
export declare const collectLogs: (self: WorkerContext, callId: number, labels: string[]) => Promise<void>;
|
|
10
|
+
export declare const deleteLogs: (self: WorkerContext, callId: number, labels: string[], lastId: number) => Promise<void>;
|
|
11
|
+
export declare const setMaxRecords: (self: WorkerContext, callId: number, max: number) => void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.symbol.js");
|
|
4
|
+
require("core-js/modules/es.symbol.description.js");
|
|
5
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
6
|
+
require("core-js/modules/es.error.cause.js");
|
|
7
|
+
require("core-js/modules/es.error.to-string.js");
|
|
8
|
+
require("core-js/modules/es.array.from.js");
|
|
9
|
+
require("core-js/modules/es.array.is-array.js");
|
|
10
|
+
require("core-js/modules/es.array.slice.js");
|
|
11
|
+
require("core-js/modules/es.function.name.js");
|
|
12
|
+
require("core-js/modules/es.object.define-property.js");
|
|
13
|
+
require("core-js/modules/es.object.to-string.js");
|
|
14
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
15
|
+
require("core-js/modules/es.regexp.test.js");
|
|
16
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
17
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: true
|
|
20
|
+
});
|
|
21
|
+
exports.writeLog = exports.setMaxRecords = exports.deleteLogs = exports.collectLogs = void 0;
|
|
22
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
23
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
24
|
+
require("core-js/modules/es.array.concat.js");
|
|
25
|
+
require("core-js/modules/es.array.iterator.js");
|
|
26
|
+
require("core-js/modules/es.array.push.js");
|
|
27
|
+
require("core-js/modules/es.array.reverse.js");
|
|
28
|
+
require("core-js/modules/es.date.to-string.js");
|
|
29
|
+
require("core-js/modules/es.string.iterator.js");
|
|
30
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
31
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
32
|
+
var _db = require("./db");
|
|
33
|
+
var _mutex = require("../mutex");
|
|
34
|
+
var _constants = require("../constants");
|
|
35
|
+
var _reply = require("./reply");
|
|
36
|
+
var _raceCondition = require("../../utilities/race-condition");
|
|
37
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
|
38
|
+
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; } } }; }
|
|
39
|
+
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); }
|
|
40
|
+
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; }
|
|
41
|
+
var MAX_WAIT_TIME = 3000;
|
|
42
|
+
var mutex = new _mutex.Mutex();
|
|
43
|
+
var maxRecords = 50000;
|
|
44
|
+
var logsCount = 0;
|
|
45
|
+
var logs = [];
|
|
46
|
+
var writeLog = exports.writeLog = function writeLog(self, callId, log) {
|
|
47
|
+
logsCount++;
|
|
48
|
+
log.content = "[".concat(logsCount, "]").concat(log.content);
|
|
49
|
+
logs.push(log);
|
|
50
|
+
debouncedWriting();
|
|
51
|
+
// reply(self, callId, WorkerDirectives.WRITE_LOG, { isSuccess: true });
|
|
52
|
+
};
|
|
53
|
+
var debouncedWriting = (0, _debounce["default"])(function () {
|
|
54
|
+
mutex.dispatch(function () {
|
|
55
|
+
return (0, _raceCondition.timeout)((0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
56
|
+
var time1, logscopy, count, exceedNo, total, pk, time2;
|
|
57
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
58
|
+
while (1) switch (_context.prev = _context.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
time1 = new Date().getTime();
|
|
61
|
+
logscopy = logs;
|
|
62
|
+
logs = [];
|
|
63
|
+
_context.prev = 3;
|
|
64
|
+
_context.next = 6;
|
|
65
|
+
return _db.db.logs.count();
|
|
66
|
+
case 6:
|
|
67
|
+
count = _context.sent;
|
|
68
|
+
exceedNo = logscopy.length + count - maxRecords;
|
|
69
|
+
if (!(exceedNo > 0)) {
|
|
70
|
+
_context.next = 15;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
console.log("[worker] the count of stored logs exceeded limit of ".concat(maxRecords, " for ").concat(exceedNo, "."));
|
|
74
|
+
console.log("[worker] start deleting records. exceeded: ".concat(exceedNo));
|
|
75
|
+
_context.next = 13;
|
|
76
|
+
return _db.db.logs.orderBy(':id').reverse().limit(exceedNo)["delete"]();
|
|
77
|
+
case 13:
|
|
78
|
+
total = _context.sent;
|
|
79
|
+
console.log("[worker] done deleting records. total: ".concat(total));
|
|
80
|
+
case 15:
|
|
81
|
+
_context.next = 20;
|
|
82
|
+
break;
|
|
83
|
+
case 17:
|
|
84
|
+
_context.prev = 17;
|
|
85
|
+
_context.t0 = _context["catch"](3);
|
|
86
|
+
console.error("[worker] clear db failed.", _context.t0);
|
|
87
|
+
case 20:
|
|
88
|
+
_context.prev = 20;
|
|
89
|
+
console.log("[worker] start writing logs. total: ".concat(logscopy.length));
|
|
90
|
+
_context.next = 24;
|
|
91
|
+
return _db.db.logs.bulkPut(logscopy);
|
|
92
|
+
case 24:
|
|
93
|
+
pk = _context.sent;
|
|
94
|
+
time2 = new Date().getTime();
|
|
95
|
+
console.log("[worker] done writing logs in ".concat(time2 - time1, "ms. total: ").concat(logscopy.length, ", lastId: ").concat(pk));
|
|
96
|
+
_context.next = 32;
|
|
97
|
+
break;
|
|
98
|
+
case 29:
|
|
99
|
+
_context.prev = 29;
|
|
100
|
+
_context.t1 = _context["catch"](20);
|
|
101
|
+
console.error("[worker] bulkPut ".concat(logscopy.length, " failed."), _context.t1);
|
|
102
|
+
case 32:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context.stop();
|
|
105
|
+
}
|
|
106
|
+
}, _callee, null, [[3, 17], [20, 29]]);
|
|
107
|
+
}))(), MAX_WAIT_TIME);
|
|
108
|
+
})["catch"](function (e) {
|
|
109
|
+
console.log('[worker] an error during dispatching writeLog', e);
|
|
110
|
+
});
|
|
111
|
+
}, 2 * 1000, {
|
|
112
|
+
maxWait: 30 * 1000
|
|
113
|
+
});
|
|
114
|
+
var collectLogs = exports.collectLogs = /*#__PURE__*/function () {
|
|
115
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(self, callId, labels) {
|
|
116
|
+
var blob, lastId, _iterator, _step, _loop, buffer;
|
|
117
|
+
return _regenerator["default"].wrap(function _callee2$(_context3) {
|
|
118
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
119
|
+
case 0:
|
|
120
|
+
blob = new Blob();
|
|
121
|
+
lastId = 0;
|
|
122
|
+
_context3.prev = 2;
|
|
123
|
+
_iterator = _createForOfIteratorHelper(labels);
|
|
124
|
+
_context3.prev = 4;
|
|
125
|
+
_loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
|
|
126
|
+
var label, logsStr, count, zip;
|
|
127
|
+
return _regenerator["default"].wrap(function _loop$(_context2) {
|
|
128
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
129
|
+
case 0:
|
|
130
|
+
label = _step.value;
|
|
131
|
+
logsStr = '';
|
|
132
|
+
count = 0;
|
|
133
|
+
_context2.next = 5;
|
|
134
|
+
return _db.db.logs.where('label').equals(label).each(function (e) {
|
|
135
|
+
count++;
|
|
136
|
+
logsStr += e.content + '\n';
|
|
137
|
+
if (e.id > lastId) lastId = e.id;
|
|
138
|
+
});
|
|
139
|
+
case 5:
|
|
140
|
+
zip = new _jszip["default"]();
|
|
141
|
+
zip.file("".concat(label, "-logs.txt"), logsStr);
|
|
142
|
+
_context2.next = 9;
|
|
143
|
+
return zip.generateAsync({
|
|
144
|
+
type: 'blob'
|
|
145
|
+
});
|
|
146
|
+
case 9:
|
|
147
|
+
blob = _context2.sent;
|
|
148
|
+
console.log("[worker] collected ".concat(count, " logs by labels [").concat(label, "]."));
|
|
149
|
+
case 11:
|
|
150
|
+
case "end":
|
|
151
|
+
return _context2.stop();
|
|
152
|
+
}
|
|
153
|
+
}, _loop);
|
|
154
|
+
});
|
|
155
|
+
_iterator.s();
|
|
156
|
+
case 7:
|
|
157
|
+
if ((_step = _iterator.n()).done) {
|
|
158
|
+
_context3.next = 11;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
return _context3.delegateYield(_loop(), "t0", 9);
|
|
162
|
+
case 9:
|
|
163
|
+
_context3.next = 7;
|
|
164
|
+
break;
|
|
165
|
+
case 11:
|
|
166
|
+
_context3.next = 16;
|
|
167
|
+
break;
|
|
168
|
+
case 13:
|
|
169
|
+
_context3.prev = 13;
|
|
170
|
+
_context3.t1 = _context3["catch"](4);
|
|
171
|
+
_iterator.e(_context3.t1);
|
|
172
|
+
case 16:
|
|
173
|
+
_context3.prev = 16;
|
|
174
|
+
_iterator.f();
|
|
175
|
+
return _context3.finish(16);
|
|
176
|
+
case 19:
|
|
177
|
+
_context3.next = 25;
|
|
178
|
+
break;
|
|
179
|
+
case 21:
|
|
180
|
+
_context3.prev = 21;
|
|
181
|
+
_context3.t2 = _context3["catch"](2);
|
|
182
|
+
console.error("[worker] failed to collect logs.", _context3.t2);
|
|
183
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.COLLECT_LOGS, {
|
|
184
|
+
isSuccess: false
|
|
185
|
+
});
|
|
186
|
+
case 25:
|
|
187
|
+
console.log("[worker] completed collecting logs, compressed size: ".concat(blob.size, " bytes."));
|
|
188
|
+
_context3.next = 28;
|
|
189
|
+
return blob.arrayBuffer();
|
|
190
|
+
case 28:
|
|
191
|
+
buffer = _context3.sent;
|
|
192
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.COLLECT_LOGS, {
|
|
193
|
+
isSuccess: true,
|
|
194
|
+
buffer: buffer,
|
|
195
|
+
lastId: lastId
|
|
196
|
+
}, [buffer]);
|
|
197
|
+
case 30:
|
|
198
|
+
case "end":
|
|
199
|
+
return _context3.stop();
|
|
200
|
+
}
|
|
201
|
+
}, _callee2, null, [[2, 21], [4, 13, 16, 19]]);
|
|
202
|
+
}));
|
|
203
|
+
return function collectLogs(_x, _x2, _x3) {
|
|
204
|
+
return _ref2.apply(this, arguments);
|
|
205
|
+
};
|
|
206
|
+
}();
|
|
207
|
+
var deleteLogs = exports.deleteLogs = /*#__PURE__*/function () {
|
|
208
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(self, callId, labels, lastId) {
|
|
209
|
+
var count;
|
|
210
|
+
return _regenerator["default"].wrap(function _callee3$(_context4) {
|
|
211
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
212
|
+
case 0:
|
|
213
|
+
_context4.prev = 0;
|
|
214
|
+
_context4.next = 3;
|
|
215
|
+
return _db.db.logs.where('id').belowOrEqual(lastId)["delete"]();
|
|
216
|
+
case 3:
|
|
217
|
+
count = _context4.sent;
|
|
218
|
+
console.log("[logger] deleted ".concat(count, " logs from ").concat(lastId, "."));
|
|
219
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.DELETE_LOGS, {
|
|
220
|
+
isSuccess: true
|
|
221
|
+
});
|
|
222
|
+
_context4.next = 12;
|
|
223
|
+
break;
|
|
224
|
+
case 8:
|
|
225
|
+
_context4.prev = 8;
|
|
226
|
+
_context4.t0 = _context4["catch"](0);
|
|
227
|
+
console.error("[logger] failed to delete logs.", _context4.t0);
|
|
228
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.DELETE_LOGS, {
|
|
229
|
+
isSuccess: false
|
|
230
|
+
});
|
|
231
|
+
case 12:
|
|
232
|
+
case "end":
|
|
233
|
+
return _context4.stop();
|
|
234
|
+
}
|
|
235
|
+
}, _callee3, null, [[0, 8]]);
|
|
236
|
+
}));
|
|
237
|
+
return function deleteLogs(_x4, _x5, _x6, _x7) {
|
|
238
|
+
return _ref3.apply(this, arguments);
|
|
239
|
+
};
|
|
240
|
+
}();
|
|
241
|
+
var setMaxRecords = exports.setMaxRecords = function setMaxRecords(self, callId, max) {
|
|
242
|
+
maxRecords = max;
|
|
243
|
+
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.SET_MAX_RECORDS, {
|
|
244
|
+
isSuccess: true
|
|
245
|
+
});
|
|
246
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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.reply = void 0;
|
|
8
|
+
var reply = exports.reply = function reply(self, callId, type, data, transfer) {
|
|
9
|
+
if (transfer) {
|
|
10
|
+
self.postMessage({
|
|
11
|
+
type: type,
|
|
12
|
+
callId: callId,
|
|
13
|
+
data: data
|
|
14
|
+
}, transfer);
|
|
15
|
+
} else {
|
|
16
|
+
self.postMessage({
|
|
17
|
+
type: type,
|
|
18
|
+
callId: callId,
|
|
19
|
+
data: data
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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.getWorkerSingleton = void 0;
|
|
8
|
+
var _interactor = require("./interactor");
|
|
9
|
+
var singleton;
|
|
10
|
+
var getWorkerSingleton = exports.getWorkerSingleton = function getWorkerSingleton() {
|
|
11
|
+
if (!singleton) {
|
|
12
|
+
singleton = new _interactor.WorkerInteractor();
|
|
13
|
+
}
|
|
14
|
+
return singleton;
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LogWorkerInteractor } from '../logger/type';
|
|
3
|
+
export declare class WorkerInteractor implements LogWorkerInteractor {
|
|
4
|
+
private _eventEmitter;
|
|
5
|
+
private _logWorker;
|
|
6
|
+
constructor();
|
|
7
|
+
clearTempLogs(): Promise<void>;
|
|
8
|
+
setMaxRecords(maxRecords: number): Promise<void>;
|
|
9
|
+
sendLog(message: string, label: string): void;
|
|
10
|
+
collectLogs(labels: string[]): Promise<{
|
|
11
|
+
file: File;
|
|
12
|
+
lastId: number;
|
|
13
|
+
}>;
|
|
14
|
+
deleteLogs(labels: string[], lastId: number): Promise<void>;
|
|
15
|
+
persistBinary(id: number, buffer: Buffer): Promise<void>;
|
|
16
|
+
unpersistBinary(id: number): Promise<void>;
|
|
17
|
+
getBinary(id: number): Promise<Buffer | null>;
|
|
18
|
+
collectLogsOnFs(logDirPath: string): Promise<File>;
|
|
19
|
+
private _handleMessageCallback;
|
|
20
|
+
private _handleErrorCallback;
|
|
21
|
+
private _handleMessageErrorCallback;
|
|
22
|
+
private _attachEventHandlers;
|
|
23
|
+
private _spawnNewWorker;
|
|
24
|
+
private _promisify;
|
|
25
|
+
}
|