@stemy/backend 3.0.0 → 3.1.1
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/bundles/stemy-backend.umd.js +231 -149
- package/bundles/stemy-backend.umd.js.map +1 -1
- package/bundles/stemy-backend.umd.min.js +1 -1
- package/bundles/stemy-backend.umd.min.js.map +1 -1
- package/common-types.d.ts +13 -4
- package/esm2015/common-types.js +1 -1
- package/esm2015/public_api.js +5 -4
- package/esm2015/services/entities/lazy-asset.js +6 -7
- package/esm2015/services/entities/progress.js +18 -6
- package/esm2015/services/job-manager.js +81 -47
- package/esm2015/services/lazy-assets.js +7 -5
- package/esm2015/services/progresses.js +54 -30
- package/esm2015/utilities/lazy-asset-generator.js +4 -3
- package/esm2015/utils.js +9 -3
- package/fesm2015/stemy-backend.js +171 -93
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +2 -2
- package/services/entities/lazy-asset.d.ts +2 -4
- package/services/entities/progress.d.ts +6 -4
- package/services/job-manager.d.ts +15 -8
- package/services/progresses.d.ts +9 -7
- package/stemy-backend.metadata.json +1 -1
- package/utilities/lazy-asset-generator.d.ts +3 -3
- package/utils.d.ts +5 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.
|
|
5
|
-
})(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeCron, zeromq,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('rxjs/operators'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', 'rxjs/operators', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', 'bcrypt', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.rxjs.operators, global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
|
|
5
|
+
})(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeCron, zeromq, operators, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
var sharp___default = /*#__PURE__*/_interopDefaultLegacy(sharp_);
|
|
29
29
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
30
30
|
var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
|
|
31
|
-
var socket_io_client__default = /*#__PURE__*/_interopDefaultLegacy(socket_io_client);
|
|
32
31
|
var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
|
|
33
32
|
var socket_io__default = /*#__PURE__*/_interopDefaultLegacy(socket_io);
|
|
34
33
|
var Handlebars__namespace = /*#__PURE__*/_interopNamespace(Handlebars);
|
|
@@ -1081,6 +1080,7 @@
|
|
|
1081
1080
|
ConsoleColor["FgMagenta"] = "\u001B[35m";
|
|
1082
1081
|
ConsoleColor["FgCyan"] = "\u001B[36m";
|
|
1083
1082
|
ConsoleColor["FgWhite"] = "\u001B[37m";
|
|
1083
|
+
ConsoleColor["FgDefault"] = "\u001B[38m";
|
|
1084
1084
|
ConsoleColor["BgBlack"] = "\u001B[40m";
|
|
1085
1085
|
ConsoleColor["BgRed"] = "\u001B[41m";
|
|
1086
1086
|
ConsoleColor["BgGreen"] = "\u001B[42m";
|
|
@@ -1089,15 +1089,20 @@
|
|
|
1089
1089
|
ConsoleColor["BgMagenta"] = "\u001B[45m";
|
|
1090
1090
|
ConsoleColor["BgCyan"] = "\u001B[46m";
|
|
1091
1091
|
ConsoleColor["BgWhite"] = "\u001B[47m";
|
|
1092
|
+
ConsoleColor["BgDefault"] = "\u001B[48m";
|
|
1092
1093
|
})(exports.ConsoleColor || (exports.ConsoleColor = {}));
|
|
1093
1094
|
var defaultColors = {
|
|
1094
|
-
keyColor: exports.ConsoleColor.
|
|
1095
|
+
keyColor: exports.ConsoleColor.FgWhite,
|
|
1095
1096
|
numberColor: exports.ConsoleColor.FgBlue,
|
|
1096
|
-
stringColor: exports.ConsoleColor.
|
|
1097
|
+
stringColor: exports.ConsoleColor.FgYellow,
|
|
1097
1098
|
trueColor: exports.ConsoleColor.FgGreen,
|
|
1098
1099
|
falseColor: exports.ConsoleColor.FgRed,
|
|
1099
1100
|
nullColor: exports.ConsoleColor.BgMagenta
|
|
1100
1101
|
};
|
|
1102
|
+
var MAX_TIMEOUT = 120000;
|
|
1103
|
+
function colorize(input, color) {
|
|
1104
|
+
return "" + color + input + exports.ConsoleColor.Reset;
|
|
1105
|
+
}
|
|
1101
1106
|
function jsonHighlight(input, colorOptions) {
|
|
1102
1107
|
var colors = Object.assign({}, defaultColors, colorOptions);
|
|
1103
1108
|
var json = (isString(input) ? input : JSON.stringify(input, null, 2)).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
@@ -2204,11 +2209,10 @@
|
|
|
2204
2209
|
};
|
|
2205
2210
|
var LazyAsset = /** @class */ (function (_super) {
|
|
2206
2211
|
__extends(LazyAsset, _super);
|
|
2207
|
-
function LazyAsset(id, data, collection, assets, progresses
|
|
2212
|
+
function LazyAsset(id, data, collection, assets, progresses) {
|
|
2208
2213
|
var _this = _super.call(this, id, data, collection) || this;
|
|
2209
2214
|
_this.assets = assets;
|
|
2210
2215
|
_this.progresses = progresses;
|
|
2211
|
-
_this.jobMan = jobMan;
|
|
2212
2216
|
return _this;
|
|
2213
2217
|
}
|
|
2214
2218
|
Object.defineProperty(LazyAsset.prototype, "jobName", {
|
|
@@ -2271,7 +2275,7 @@
|
|
|
2271
2275
|
_this.progresses.get(_this.progressId).then(function (p) {
|
|
2272
2276
|
p === null || p === void 0 ? void 0 : p.cancel();
|
|
2273
2277
|
});
|
|
2274
|
-
_this.startWorkingOnAsset().then(function () {
|
|
2278
|
+
_this.startWorkingOnAsset(false).then(function () {
|
|
2275
2279
|
console.log("Started working on lazy asset: " + _this.id);
|
|
2276
2280
|
}).catch(function (reason) {
|
|
2277
2281
|
console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
|
|
@@ -2295,7 +2299,7 @@
|
|
|
2295
2299
|
case 2:
|
|
2296
2300
|
_a.sent();
|
|
2297
2301
|
return [2 /*return*/, this.loadAsset()];
|
|
2298
|
-
case 3: return [4 /*yield*/, this.startWorkingOnAsset()];
|
|
2302
|
+
case 3: return [4 /*yield*/, this.startWorkingOnAsset(true)];
|
|
2299
2303
|
case 4:
|
|
2300
2304
|
_a.sent();
|
|
2301
2305
|
return [2 /*return*/, this.loadAsset()];
|
|
@@ -2317,7 +2321,7 @@
|
|
|
2317
2321
|
});
|
|
2318
2322
|
});
|
|
2319
2323
|
};
|
|
2320
|
-
LazyAsset.prototype.startWorkingOnAsset = function () {
|
|
2324
|
+
LazyAsset.prototype.startWorkingOnAsset = function (fromLoad) {
|
|
2321
2325
|
return __awaiter$p(this, void 0, void 0, function () {
|
|
2322
2326
|
var _a;
|
|
2323
2327
|
return __generator(this, function (_b) {
|
|
@@ -2331,7 +2335,7 @@
|
|
|
2331
2335
|
return [4 /*yield*/, this.save()];
|
|
2332
2336
|
case 2:
|
|
2333
2337
|
_b.sent();
|
|
2334
|
-
return [4 /*yield*/, this.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id }))];
|
|
2338
|
+
return [4 /*yield*/, this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id, fromLoad: fromLoad }))];
|
|
2335
2339
|
case 3:
|
|
2336
2340
|
_b.sent();
|
|
2337
2341
|
return [2 /*return*/];
|
|
@@ -2387,11 +2391,23 @@
|
|
|
2387
2391
|
this.jobs = this.jobTypes.reduce(function (res, jobType) {
|
|
2388
2392
|
res[getConstructorName(jobType)] = function (jobParams) {
|
|
2389
2393
|
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2390
|
-
return job.process();
|
|
2394
|
+
return job.process(_this.messageBridge);
|
|
2391
2395
|
};
|
|
2392
2396
|
return res;
|
|
2393
2397
|
}, {});
|
|
2398
|
+
this.messages = new rxjs.Subject();
|
|
2399
|
+
this.messageBridge = {
|
|
2400
|
+
sendMessage: function (message, params) {
|
|
2401
|
+
_this.workerPush.send([message, JSON.stringify(params)]);
|
|
2402
|
+
}
|
|
2403
|
+
};
|
|
2404
|
+
this.processing = false;
|
|
2394
2405
|
}
|
|
2406
|
+
JobManager.prototype.on = function (message, cb) {
|
|
2407
|
+
return this.messages
|
|
2408
|
+
.pipe(operators.filter(function (t) { return t.message === message; }))
|
|
2409
|
+
.pipe(operators.map(function (t) { return t.params; })).subscribe(cb);
|
|
2410
|
+
};
|
|
2395
2411
|
JobManager.prototype.process = function (jobType, params) {
|
|
2396
2412
|
if (params === void 0) { params = {}; }
|
|
2397
2413
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
@@ -2412,44 +2428,16 @@
|
|
|
2412
2428
|
JobManager.prototype.enqueueWithName = function (name, params) {
|
|
2413
2429
|
if (params === void 0) { params = {}; }
|
|
2414
2430
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2415
|
-
var jobName;
|
|
2416
2431
|
return __generator(this, function (_a) {
|
|
2417
|
-
|
|
2418
|
-
case 0: return [4 /*yield*/, this.tryResolveFromName(name, params)];
|
|
2419
|
-
case 1:
|
|
2420
|
-
jobName = _a.sent();
|
|
2421
|
-
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2422
|
-
}
|
|
2432
|
+
return [2 /*return*/, this.sendToWorkers(this.tryResolveFromName(name, params), params)];
|
|
2423
2433
|
});
|
|
2424
2434
|
});
|
|
2425
2435
|
};
|
|
2426
2436
|
JobManager.prototype.enqueue = function (jobType, params) {
|
|
2427
2437
|
if (params === void 0) { params = {}; }
|
|
2428
2438
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2429
|
-
var jobName;
|
|
2430
|
-
return __generator(this, function (_a) {
|
|
2431
|
-
switch (_a.label) {
|
|
2432
|
-
case 0: return [4 /*yield*/, this.tryResolveAndConnect(jobType, params)];
|
|
2433
|
-
case 1:
|
|
2434
|
-
jobName = _a.sent();
|
|
2435
|
-
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2436
|
-
}
|
|
2437
|
-
});
|
|
2438
|
-
});
|
|
2439
|
-
};
|
|
2440
|
-
JobManager.prototype.sendToWorkers = function (jobName, params) {
|
|
2441
|
-
return __awaiter$o(this, void 0, void 0, function () {
|
|
2442
|
-
var publisher;
|
|
2443
2439
|
return __generator(this, function (_a) {
|
|
2444
|
-
|
|
2445
|
-
case 0: return [4 /*yield*/, this.scheduler];
|
|
2446
|
-
case 1:
|
|
2447
|
-
publisher = _a.sent();
|
|
2448
|
-
return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
|
|
2449
|
-
case 2:
|
|
2450
|
-
_a.sent();
|
|
2451
|
-
return [2 /*return*/];
|
|
2452
|
-
}
|
|
2440
|
+
return [2 /*return*/, this.sendToWorkers(this.tryResolveAndInit(jobType, params), params)];
|
|
2453
2441
|
});
|
|
2454
2442
|
});
|
|
2455
2443
|
};
|
|
@@ -2478,47 +2466,71 @@
|
|
|
2478
2466
|
});
|
|
2479
2467
|
};
|
|
2480
2468
|
JobManager.prototype.startProcessing = function () {
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
this.worker.connect(host);
|
|
2485
|
-
this.worker.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2486
|
-
var jobName, jobParams, timerId, jobNameLog, jobArgsLog, e_1, e_2;
|
|
2469
|
+
return __awaiter$o(this, void 0, void 0, function () {
|
|
2470
|
+
var host, pushHost, pullHost;
|
|
2471
|
+
var _this = this;
|
|
2487
2472
|
return __generator(this, function (_a) {
|
|
2488
2473
|
switch (_a.label) {
|
|
2489
2474
|
case 0:
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2475
|
+
if (this.processing)
|
|
2476
|
+
return [2 /*return*/, null];
|
|
2477
|
+
this.processing = true;
|
|
2478
|
+
if (!this.config.resolve("isWorker")) {
|
|
2479
|
+
console.log(colorize("Processing can not be started because this is NOT a worker process!", exports.ConsoleColor.FgRed));
|
|
2480
|
+
return [2 /*return*/, null];
|
|
2481
|
+
}
|
|
2482
|
+
host = this.config.resolve("zmqRemoteHost");
|
|
2483
|
+
pushHost = host + ":" + this.config.resolve("zmqBackPort");
|
|
2484
|
+
this.workerPush = zeromq.socket("push");
|
|
2485
|
+
return [4 /*yield*/, this.workerPush.connect(pushHost)];
|
|
2499
2486
|
case 1:
|
|
2500
|
-
_a.
|
|
2501
|
-
|
|
2487
|
+
_a.sent();
|
|
2488
|
+
console.log("Worker producer connected to: " + pushHost);
|
|
2489
|
+
pullHost = host + ":" + this.config.resolve("zmqPort");
|
|
2490
|
+
this.workerPull = zeromq.socket("pull");
|
|
2491
|
+
return [4 /*yield*/, this.workerPull.connect(pullHost)];
|
|
2502
2492
|
case 2:
|
|
2503
2493
|
_a.sent();
|
|
2504
|
-
console.
|
|
2505
|
-
return
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2494
|
+
console.log("Worker consumer connected to: " + pullHost);
|
|
2495
|
+
this.workerPull.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2496
|
+
var jobName, jobParams, timerId, e_1, e_2;
|
|
2497
|
+
return __generator(this, function (_a) {
|
|
2498
|
+
switch (_a.label) {
|
|
2499
|
+
case 0:
|
|
2500
|
+
_a.trys.push([0, 5, , 6]);
|
|
2501
|
+
jobName = name.toString("utf8");
|
|
2502
|
+
jobParams = JSON.parse(args.toString("utf8"));
|
|
2503
|
+
timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
|
|
2504
|
+
console.time(timerId);
|
|
2505
|
+
console.timeLog(timerId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
|
|
2506
|
+
this.messageBridge.sendMessage("job-started", { name: jobName });
|
|
2507
|
+
_a.label = 1;
|
|
2508
|
+
case 1:
|
|
2509
|
+
_a.trys.push([1, 3, , 4]);
|
|
2510
|
+
return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(MAX_TIMEOUT, true)])];
|
|
2511
|
+
case 2:
|
|
2512
|
+
_a.sent();
|
|
2513
|
+
console.timeLog(timerId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
|
|
2514
|
+
return [3 /*break*/, 4];
|
|
2515
|
+
case 3:
|
|
2516
|
+
e_1 = _a.sent();
|
|
2517
|
+
console.timeLog(timerId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
|
|
2518
|
+
return [3 /*break*/, 4];
|
|
2519
|
+
case 4:
|
|
2520
|
+
console.timeEnd(timerId);
|
|
2521
|
+
return [3 /*break*/, 6];
|
|
2522
|
+
case 5:
|
|
2523
|
+
e_2 = _a.sent();
|
|
2524
|
+
console.log("Failed to start job: " + e_2.message);
|
|
2525
|
+
return [3 /*break*/, 6];
|
|
2526
|
+
case 6: return [2 /*return*/];
|
|
2527
|
+
}
|
|
2528
|
+
});
|
|
2529
|
+
}); });
|
|
2530
|
+
return [2 /*return*/];
|
|
2518
2531
|
}
|
|
2519
2532
|
});
|
|
2520
|
-
});
|
|
2521
|
-
console.log("Waiting for jobs at: " + host);
|
|
2533
|
+
});
|
|
2522
2534
|
};
|
|
2523
2535
|
JobManager.prototype.tryResolve = function (jobType, params) {
|
|
2524
2536
|
var jobName = getConstructorName(jobType);
|
|
@@ -2540,31 +2552,29 @@
|
|
|
2540
2552
|
if (!jobType) {
|
|
2541
2553
|
throw "Can't find job type with name: " + jobName + " so it can't be enqueued!";
|
|
2542
2554
|
}
|
|
2543
|
-
return this.
|
|
2555
|
+
return this.tryResolveAndInit(jobType, params);
|
|
2544
2556
|
};
|
|
2545
|
-
JobManager.prototype.
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
}
|
|
2563
|
-
});
|
|
2564
|
-
}); });
|
|
2565
|
-
return [2 /*return*/, this.tryResolve(jobType, params)];
|
|
2557
|
+
JobManager.prototype.tryResolveAndInit = function (jobType, params) {
|
|
2558
|
+
var _this = this;
|
|
2559
|
+
if (!this.apiPush) {
|
|
2560
|
+
var port = this.config.resolve("zmqPort");
|
|
2561
|
+
this.apiPush = zeromq.socket("push");
|
|
2562
|
+
this.apiPush.bind("tcp://0.0.0.0:" + port);
|
|
2563
|
+
console.log("API producer bound to port: " + port);
|
|
2564
|
+
}
|
|
2565
|
+
if (!this.apiPull) {
|
|
2566
|
+
var backPort = this.config.resolve("zmqBackPort");
|
|
2567
|
+
this.apiPull = zeromq.socket("pull");
|
|
2568
|
+
this.apiPull.bind("tcp://0.0.0.0:" + backPort);
|
|
2569
|
+
this.apiPull.on("message", function (name, args) {
|
|
2570
|
+
var message = name.toString("utf8");
|
|
2571
|
+
var params = JSON.parse((args === null || args === void 0 ? void 0 : args.toString("utf8")) || "{}");
|
|
2572
|
+
console.log("Received a message from worker: \"" + colorize(message, exports.ConsoleColor.FgCyan) + "\" with args: " + jsonHighlight(params) + "\n\n");
|
|
2573
|
+
_this.messages.next({ message: message, params: params });
|
|
2566
2574
|
});
|
|
2567
|
-
|
|
2575
|
+
console.log("API consumer bound to port: " + backPort);
|
|
2576
|
+
}
|
|
2577
|
+
return this.tryResolve(jobType, params);
|
|
2568
2578
|
};
|
|
2569
2579
|
JobManager.prototype.resolveJobInstance = function (jobType, params) {
|
|
2570
2580
|
var container = this.container.createChildContainer();
|
|
@@ -2574,6 +2584,22 @@
|
|
|
2574
2584
|
container.register(jobType, jobType);
|
|
2575
2585
|
return container.resolve(jobType);
|
|
2576
2586
|
};
|
|
2587
|
+
JobManager.prototype.sendToWorkers = function (jobName, params) {
|
|
2588
|
+
return __awaiter$o(this, void 0, void 0, function () {
|
|
2589
|
+
var publisher;
|
|
2590
|
+
return __generator(this, function (_a) {
|
|
2591
|
+
switch (_a.label) {
|
|
2592
|
+
case 0: return [4 /*yield*/, this.apiPush];
|
|
2593
|
+
case 1:
|
|
2594
|
+
publisher = _a.sent();
|
|
2595
|
+
return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
|
|
2596
|
+
case 2:
|
|
2597
|
+
_a.sent();
|
|
2598
|
+
return [2 /*return*/];
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2601
|
+
});
|
|
2602
|
+
};
|
|
2577
2603
|
return JobManager;
|
|
2578
2604
|
}());
|
|
2579
2605
|
exports.JobManager = __decorate$s([
|
|
@@ -2604,10 +2630,8 @@
|
|
|
2604
2630
|
};
|
|
2605
2631
|
var Progress = /** @class */ (function (_super) {
|
|
2606
2632
|
__extends(Progress, _super);
|
|
2607
|
-
function Progress(id, data, collection
|
|
2608
|
-
|
|
2609
|
-
_this.client = client;
|
|
2610
|
-
return _this;
|
|
2633
|
+
function Progress(id, data, collection) {
|
|
2634
|
+
return _super.call(this, id, data, collection) || this;
|
|
2611
2635
|
}
|
|
2612
2636
|
Object.defineProperty(Progress.prototype, "current", {
|
|
2613
2637
|
get: function () {
|
|
@@ -2658,6 +2682,10 @@
|
|
|
2658
2682
|
enumerable: false,
|
|
2659
2683
|
configurable: true
|
|
2660
2684
|
});
|
|
2685
|
+
Progress.prototype.setMessageBridge = function (messageBridge) {
|
|
2686
|
+
this.messageBridge = messageBridge || this.messageBridge;
|
|
2687
|
+
return this;
|
|
2688
|
+
};
|
|
2661
2689
|
Progress.prototype.createSubProgress = function (progressValue, max, message) {
|
|
2662
2690
|
return __awaiter$n(this, void 0, void 0, function () {
|
|
2663
2691
|
return __generator(this, function (_a) {
|
|
@@ -2743,9 +2771,6 @@
|
|
|
2743
2771
|
return [4 /*yield*/, this.save()];
|
|
2744
2772
|
case 2:
|
|
2745
2773
|
_a.sent();
|
|
2746
|
-
if (!this.client)
|
|
2747
|
-
return [2 /*return*/];
|
|
2748
|
-
this.client.emit("background-progress", this.id);
|
|
2749
2774
|
return [2 /*return*/];
|
|
2750
2775
|
}
|
|
2751
2776
|
});
|
|
@@ -2765,6 +2790,12 @@
|
|
|
2765
2790
|
});
|
|
2766
2791
|
});
|
|
2767
2792
|
};
|
|
2793
|
+
Progress.prototype.save = function () {
|
|
2794
|
+
if (this.messageBridge) {
|
|
2795
|
+
this.messageBridge.sendMessage("progress-changed", this.toJSON());
|
|
2796
|
+
}
|
|
2797
|
+
return _super.prototype.save.call(this);
|
|
2798
|
+
};
|
|
2768
2799
|
return Progress;
|
|
2769
2800
|
}(BaseEntity));
|
|
2770
2801
|
var SubProgress = /** @class */ (function () {
|
|
@@ -2838,6 +2869,12 @@
|
|
|
2838
2869
|
enumerable: false,
|
|
2839
2870
|
configurable: true
|
|
2840
2871
|
});
|
|
2872
|
+
SubProgress.prototype.setMessageBridge = function (messageBridge) {
|
|
2873
|
+
if (!this.parent)
|
|
2874
|
+
return this;
|
|
2875
|
+
this.parent.setMessageBridge(messageBridge);
|
|
2876
|
+
return this;
|
|
2877
|
+
};
|
|
2841
2878
|
SubProgress.prototype.createSubProgress = function (progressValue, max, message) {
|
|
2842
2879
|
return __awaiter$n(this, void 0, void 0, function () {
|
|
2843
2880
|
return __generator(this, function (_a) {
|
|
@@ -3004,44 +3041,48 @@
|
|
|
3004
3041
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3005
3042
|
});
|
|
3006
3043
|
};
|
|
3007
|
-
var socketIOClient = socket_io_client__default["default"];
|
|
3008
3044
|
exports.Progresses = /** @class */ (function () {
|
|
3009
|
-
function Progresses(connector,
|
|
3045
|
+
function Progresses(connector, jobMan) {
|
|
3046
|
+
var _this = this;
|
|
3010
3047
|
this.connector = connector;
|
|
3011
|
-
this.
|
|
3012
|
-
var mainEndpoint = this.config.resolve("mainEndpoint");
|
|
3013
|
-
this.client = !mainEndpoint ? null : socketIOClient(mainEndpoint, { path: "/socket" });
|
|
3048
|
+
this.jobMan = jobMan;
|
|
3014
3049
|
this.collection = connector.database.collection("progresses");
|
|
3050
|
+
this.progresses = {};
|
|
3051
|
+
this.jobMan.on("progress-changed", function (progress) {
|
|
3052
|
+
var id = progress.id;
|
|
3053
|
+
_this.progresses[id] = new Progress(new bson.ObjectId(id), progress, _this.collection);
|
|
3054
|
+
});
|
|
3015
3055
|
}
|
|
3016
3056
|
Progresses.prototype.waitToFinish = function (id) {
|
|
3017
3057
|
return __awaiter$m(this, void 0, void 0, function () {
|
|
3018
|
-
var
|
|
3058
|
+
var _this = this;
|
|
3019
3059
|
return __generator(this, function (_a) {
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3060
|
+
return [2 /*return*/, Promise.race([
|
|
3061
|
+
this.waitForProgress(id, function () { return __awaiter$m(_this, void 0, void 0, function () {
|
|
3062
|
+
var progress;
|
|
3063
|
+
return __generator(this, function (_a) {
|
|
3064
|
+
switch (_a.label) {
|
|
3065
|
+
case 0:
|
|
3066
|
+
progress = this.progresses[id];
|
|
3067
|
+
if (!(!progress || progress.percent < 100)) return [3 /*break*/, 2];
|
|
3068
|
+
return [4 /*yield*/, this.get(id)];
|
|
3069
|
+
case 1:
|
|
3070
|
+
progress = _a.sent();
|
|
3071
|
+
_a.label = 2;
|
|
3072
|
+
case 2:
|
|
3073
|
+
if (!progress) {
|
|
3074
|
+
throw new Error("Progress does not exists with id: " + id);
|
|
3075
|
+
}
|
|
3076
|
+
return [2 /*return*/, progress];
|
|
3077
|
+
}
|
|
3078
|
+
});
|
|
3079
|
+
}); }, 500),
|
|
3080
|
+
this.waitForProgress(id, function () { return __awaiter$m(_this, void 0, void 0, function () {
|
|
3081
|
+
return __generator(this, function (_a) {
|
|
3082
|
+
return [2 /*return*/, this.progresses[id] || null];
|
|
3083
|
+
});
|
|
3084
|
+
}); }, 25)
|
|
3085
|
+
])];
|
|
3045
3086
|
});
|
|
3046
3087
|
});
|
|
3047
3088
|
};
|
|
@@ -3060,7 +3101,7 @@
|
|
|
3060
3101
|
case 0: return [4 /*yield*/, this.collection.findOne(where)];
|
|
3061
3102
|
case 1:
|
|
3062
3103
|
data = _a.sent();
|
|
3063
|
-
return [2 /*return*/, !data ? null : new Progress(data._id, data, this.collection
|
|
3104
|
+
return [2 /*return*/, !data ? null : new Progress(data._id, data, this.collection)];
|
|
3064
3105
|
}
|
|
3065
3106
|
});
|
|
3066
3107
|
});
|
|
@@ -3073,7 +3114,7 @@
|
|
|
3073
3114
|
switch (_a.label) {
|
|
3074
3115
|
case 0:
|
|
3075
3116
|
if (isNaN(max) || max <= 0) {
|
|
3076
|
-
throw "Max progress value must be bigger than zero";
|
|
3117
|
+
throw new Error("Max progress value must be bigger than zero");
|
|
3077
3118
|
}
|
|
3078
3119
|
data = {
|
|
3079
3120
|
current: 0,
|
|
@@ -3085,7 +3126,7 @@
|
|
|
3085
3126
|
return [4 /*yield*/, this.collection.insertOne(data)];
|
|
3086
3127
|
case 1:
|
|
3087
3128
|
res = _a.sent();
|
|
3088
|
-
return [2 /*return*/, new Progress(res.insertedId, data, this.collection
|
|
3129
|
+
return [2 /*return*/, new Progress(res.insertedId, data, this.collection)];
|
|
3089
3130
|
}
|
|
3090
3131
|
});
|
|
3091
3132
|
});
|
|
@@ -3102,12 +3143,48 @@
|
|
|
3102
3143
|
});
|
|
3103
3144
|
});
|
|
3104
3145
|
};
|
|
3146
|
+
Progresses.prototype.waitForProgress = function (id, cb, delay) {
|
|
3147
|
+
return __awaiter$m(this, void 0, void 0, function () {
|
|
3148
|
+
var isFinished, progress, waitTime;
|
|
3149
|
+
return __generator(this, function (_a) {
|
|
3150
|
+
switch (_a.label) {
|
|
3151
|
+
case 0:
|
|
3152
|
+
isFinished = false;
|
|
3153
|
+
progress = null;
|
|
3154
|
+
waitTime = 0;
|
|
3155
|
+
_a.label = 1;
|
|
3156
|
+
case 1:
|
|
3157
|
+
if (!!isFinished) return [3 /*break*/, 5];
|
|
3158
|
+
return [4 /*yield*/, cb()];
|
|
3159
|
+
case 2:
|
|
3160
|
+
progress = _a.sent();
|
|
3161
|
+
waitTime += delay;
|
|
3162
|
+
if (progress) {
|
|
3163
|
+
if (progress.error) {
|
|
3164
|
+
throw new Error(progress.error);
|
|
3165
|
+
}
|
|
3166
|
+
isFinished = progress.percent >= 100;
|
|
3167
|
+
}
|
|
3168
|
+
if (!!isFinished) return [3 /*break*/, 4];
|
|
3169
|
+
if (waitTime >= MAX_TIMEOUT) {
|
|
3170
|
+
throw new Error("Progress with id: " + id + " probably never will be finished!");
|
|
3171
|
+
}
|
|
3172
|
+
return [4 /*yield*/, promiseTimeout(delay)];
|
|
3173
|
+
case 3:
|
|
3174
|
+
_a.sent();
|
|
3175
|
+
_a.label = 4;
|
|
3176
|
+
case 4: return [3 /*break*/, 1];
|
|
3177
|
+
case 5: return [2 /*return*/, progress];
|
|
3178
|
+
}
|
|
3179
|
+
});
|
|
3180
|
+
});
|
|
3181
|
+
};
|
|
3105
3182
|
return Progresses;
|
|
3106
3183
|
}());
|
|
3107
3184
|
exports.Progresses = __decorate$r([
|
|
3108
3185
|
tsyringe.injectable(),
|
|
3109
3186
|
tsyringe.singleton(),
|
|
3110
|
-
__metadata$l("design:paramtypes", [exports.MongoConnector, exports.
|
|
3187
|
+
__metadata$l("design:paramtypes", [exports.MongoConnector, exports.JobManager])
|
|
3111
3188
|
], exports.Progresses);
|
|
3112
3189
|
|
|
3113
3190
|
var __decorate$q = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -3173,7 +3250,7 @@
|
|
|
3173
3250
|
return [4 /*yield*/, this.collection.insertOne(data)];
|
|
3174
3251
|
case 2:
|
|
3175
3252
|
res = _a.sent();
|
|
3176
|
-
return [2 /*return*/, new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses
|
|
3253
|
+
return [2 /*return*/, new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses)];
|
|
3177
3254
|
}
|
|
3178
3255
|
});
|
|
3179
3256
|
});
|
|
@@ -3195,7 +3272,7 @@
|
|
|
3195
3272
|
data = _a.sent();
|
|
3196
3273
|
return [2 /*return*/, !data
|
|
3197
3274
|
? null
|
|
3198
|
-
: new LazyAsset(data._id, data, this.collection, this.assets, this.progresses
|
|
3275
|
+
: new LazyAsset(data._id, data, this.collection, this.assets, this.progresses)];
|
|
3199
3276
|
}
|
|
3200
3277
|
});
|
|
3201
3278
|
});
|
|
@@ -3220,8 +3297,10 @@
|
|
|
3220
3297
|
exports.LazyAssets = __decorate$q([
|
|
3221
3298
|
tsyringe.injectable(),
|
|
3222
3299
|
tsyringe.scoped(tsyringe.Lifecycle.ContainerScoped),
|
|
3223
|
-
__metadata$k("design:paramtypes", [exports.MongoConnector,
|
|
3224
|
-
exports.
|
|
3300
|
+
__metadata$k("design:paramtypes", [exports.MongoConnector,
|
|
3301
|
+
exports.Assets,
|
|
3302
|
+
exports.Progresses,
|
|
3303
|
+
exports.JobManager])
|
|
3225
3304
|
], exports.LazyAssets);
|
|
3226
3305
|
|
|
3227
3306
|
var __decorate$p = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -5718,7 +5797,7 @@
|
|
|
5718
5797
|
enumerable: false,
|
|
5719
5798
|
configurable: true
|
|
5720
5799
|
});
|
|
5721
|
-
LazyAssetGenerator.prototype.process = function () {
|
|
5800
|
+
LazyAssetGenerator.prototype.process = function (messaging) {
|
|
5722
5801
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
5723
5802
|
var lazyAsset, progress, asset, e_1;
|
|
5724
5803
|
return __generator(this, function (_a) {
|
|
@@ -5731,10 +5810,11 @@
|
|
|
5731
5810
|
progress = _a.sent();
|
|
5732
5811
|
if (!progress || progress.canceled)
|
|
5733
5812
|
return [2 /*return*/, null];
|
|
5813
|
+
progress.setMessageBridge(messaging);
|
|
5734
5814
|
_a.label = 3;
|
|
5735
5815
|
case 3:
|
|
5736
5816
|
_a.trys.push([3, 7, , 9]);
|
|
5737
|
-
return [4 /*yield*/, this.generate(progress)];
|
|
5817
|
+
return [4 /*yield*/, this.generate(progress, messaging)];
|
|
5738
5818
|
case 4:
|
|
5739
5819
|
asset = _a.sent();
|
|
5740
5820
|
return [4 /*yield*/, progress.load()];
|
|
@@ -5835,7 +5915,8 @@
|
|
|
5835
5915
|
new Parameter("nodeEnv", "development"),
|
|
5836
5916
|
new Parameter("appPort", 80),
|
|
5837
5917
|
new Parameter("zmqPort", 3000),
|
|
5838
|
-
new Parameter("
|
|
5918
|
+
new Parameter("zmqBackPort", 3100),
|
|
5919
|
+
new Parameter("zmqRemoteHost", "tcp://127.0.0.1"),
|
|
5839
5920
|
new Parameter("isWorker", false),
|
|
5840
5921
|
new Parameter("mainEndpoint", ""),
|
|
5841
5922
|
new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
@@ -6093,6 +6174,7 @@
|
|
|
6093
6174
|
exports.assign = assign;
|
|
6094
6175
|
exports.broadcast = broadcast;
|
|
6095
6176
|
exports.bufferToStream = bufferToStream;
|
|
6177
|
+
exports.colorize = colorize;
|
|
6096
6178
|
exports.convertValue = convertValue;
|
|
6097
6179
|
exports.copy = copy;
|
|
6098
6180
|
exports.copyStream = copyStream;
|