@stemy/backend 3.1.1 → 3.1.4
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 +58 -27
- 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/esm2015/common-types.js +1 -1
- package/esm2015/public_api.js +7 -5
- package/esm2015/services/entities/temp-asset.js +1 -1
- package/esm2015/services/job-manager.js +24 -19
- package/esm2015/services/progresses.js +3 -3
- package/esm2015/utils.js +17 -2
- package/fesm2015/stemy-backend.js +45 -23
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
- package/services/job-manager.d.ts +6 -6
- package/stemy-backend.metadata.json +1 -1
- package/utils.d.ts +1 -1
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
var Handlebars__namespace = /*#__PURE__*/_interopNamespace(Handlebars);
|
|
34
34
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/******************************************************************************
|
|
37
37
|
Copyright (c) Microsoft Corporation.
|
|
38
38
|
|
|
39
39
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -195,7 +195,11 @@
|
|
|
195
195
|
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
196
196
|
if (k2 === undefined)
|
|
197
197
|
k2 = k;
|
|
198
|
-
Object.
|
|
198
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
199
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
200
|
+
desc = { enumerable: true, get: function () { return m[k]; } };
|
|
201
|
+
}
|
|
202
|
+
Object.defineProperty(o, k2, desc);
|
|
199
203
|
}) : (function (o, m, k, k2) {
|
|
200
204
|
if (k2 === undefined)
|
|
201
205
|
k2 = k;
|
|
@@ -349,6 +353,11 @@
|
|
|
349
353
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
350
354
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
351
355
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
356
|
+
}
|
|
357
|
+
function __classPrivateFieldIn(state, receiver) {
|
|
358
|
+
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
|
|
359
|
+
throw new TypeError("Cannot use 'in' operator on non-object");
|
|
360
|
+
return typeof state === "function" ? receiver === state : state.has(receiver);
|
|
352
361
|
}
|
|
353
362
|
|
|
354
363
|
var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
@@ -455,6 +464,22 @@
|
|
|
455
464
|
function lastItem(value) {
|
|
456
465
|
return value[value.length - 1];
|
|
457
466
|
}
|
|
467
|
+
function regroup(value, comparator) {
|
|
468
|
+
var result = [];
|
|
469
|
+
if (!isArray(value) || value.length == 0)
|
|
470
|
+
return result;
|
|
471
|
+
value = Array.from(value);
|
|
472
|
+
result.push([value.shift()]);
|
|
473
|
+
value.forEach(function (item) {
|
|
474
|
+
var group = result.find(function (g) { return g.some(function (a) { return comparator(a, item); }); });
|
|
475
|
+
if (group) {
|
|
476
|
+
group.push(item);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
result.push([item]);
|
|
480
|
+
});
|
|
481
|
+
return result;
|
|
482
|
+
}
|
|
458
483
|
function getValue(obj, key, defaultValue, treeFallback) {
|
|
459
484
|
if (treeFallback === void 0) { treeFallback = false; }
|
|
460
485
|
key = key || "";
|
|
@@ -1099,7 +1124,6 @@
|
|
|
1099
1124
|
falseColor: exports.ConsoleColor.FgRed,
|
|
1100
1125
|
nullColor: exports.ConsoleColor.BgMagenta
|
|
1101
1126
|
};
|
|
1102
|
-
var MAX_TIMEOUT = 120000;
|
|
1103
1127
|
function colorize(input, color) {
|
|
1104
1128
|
return "" + color + input + exports.ConsoleColor.Reset;
|
|
1105
1129
|
}
|
|
@@ -2389,19 +2413,23 @@
|
|
|
2389
2413
|
this.container = container;
|
|
2390
2414
|
this.jobTypes = jobTypes || [];
|
|
2391
2415
|
this.jobs = this.jobTypes.reduce(function (res, jobType) {
|
|
2392
|
-
|
|
2416
|
+
var jobName = getConstructorName(jobType);
|
|
2417
|
+
res[jobName] = function (jobParams, uniqueId) {
|
|
2393
2418
|
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2394
|
-
|
|
2419
|
+
var messageBridge = {
|
|
2420
|
+
sendMessage: function (message, params) {
|
|
2421
|
+
params.uniqueId = uniqueId;
|
|
2422
|
+
_this.workerPush.send([message, JSON.stringify(params)]);
|
|
2423
|
+
}
|
|
2424
|
+
};
|
|
2425
|
+
messageBridge.sendMessage("job-started", { name: jobName });
|
|
2426
|
+
return job.process(messageBridge);
|
|
2395
2427
|
};
|
|
2396
2428
|
return res;
|
|
2397
2429
|
}, {});
|
|
2398
2430
|
this.messages = new rxjs.Subject();
|
|
2399
|
-
this.messageBridge = {
|
|
2400
|
-
sendMessage: function (message, params) {
|
|
2401
|
-
_this.workerPush.send([message, JSON.stringify(params)]);
|
|
2402
|
-
}
|
|
2403
|
-
};
|
|
2404
2431
|
this.processing = false;
|
|
2432
|
+
this.maxTimeout = this.config.resolve("jobTimeout");
|
|
2405
2433
|
}
|
|
2406
2434
|
JobManager.prototype.on = function (message, cb) {
|
|
2407
2435
|
return this.messages
|
|
@@ -2492,32 +2520,31 @@
|
|
|
2492
2520
|
case 2:
|
|
2493
2521
|
_a.sent();
|
|
2494
2522
|
console.log("Worker consumer connected to: " + pullHost);
|
|
2495
|
-
this.workerPull.on("message", function (name, args,
|
|
2496
|
-
var jobName, jobParams,
|
|
2523
|
+
this.workerPull.on("message", function (name, args, uniqId) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2524
|
+
var jobName, jobParams, uniqueId, e_1, e_2;
|
|
2497
2525
|
return __generator(this, function (_a) {
|
|
2498
2526
|
switch (_a.label) {
|
|
2499
2527
|
case 0:
|
|
2500
2528
|
_a.trys.push([0, 5, , 6]);
|
|
2501
2529
|
jobName = name.toString("utf8");
|
|
2502
2530
|
jobParams = JSON.parse(args.toString("utf8"));
|
|
2503
|
-
|
|
2504
|
-
console.time(
|
|
2505
|
-
console.timeLog(
|
|
2506
|
-
this.messageBridge.sendMessage("job-started", { name: jobName });
|
|
2531
|
+
uniqueId = uniqId === null || uniqId === void 0 ? void 0 : uniqId.toString("utf8");
|
|
2532
|
+
console.time(uniqueId);
|
|
2533
|
+
console.timeLog(uniqueId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
|
|
2507
2534
|
_a.label = 1;
|
|
2508
2535
|
case 1:
|
|
2509
2536
|
_a.trys.push([1, 3, , 4]);
|
|
2510
|
-
return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(
|
|
2537
|
+
return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams, uniqueId), promiseTimeout(this.maxTimeout, true)])];
|
|
2511
2538
|
case 2:
|
|
2512
2539
|
_a.sent();
|
|
2513
|
-
console.timeLog(
|
|
2540
|
+
console.timeLog(uniqueId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
|
|
2514
2541
|
return [3 /*break*/, 4];
|
|
2515
2542
|
case 3:
|
|
2516
2543
|
e_1 = _a.sent();
|
|
2517
|
-
console.timeLog(
|
|
2544
|
+
console.timeLog(uniqueId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
|
|
2518
2545
|
return [3 /*break*/, 4];
|
|
2519
2546
|
case 4:
|
|
2520
|
-
console.timeEnd(
|
|
2547
|
+
console.timeEnd(uniqueId);
|
|
2521
2548
|
return [3 /*break*/, 6];
|
|
2522
2549
|
case 5:
|
|
2523
2550
|
e_2 = _a.sent();
|
|
@@ -2586,16 +2613,17 @@
|
|
|
2586
2613
|
};
|
|
2587
2614
|
JobManager.prototype.sendToWorkers = function (jobName, params) {
|
|
2588
2615
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2589
|
-
var publisher;
|
|
2616
|
+
var publisher, uniqueId;
|
|
2590
2617
|
return __generator(this, function (_a) {
|
|
2591
2618
|
switch (_a.label) {
|
|
2592
2619
|
case 0: return [4 /*yield*/, this.apiPush];
|
|
2593
2620
|
case 1:
|
|
2594
2621
|
publisher = _a.sent();
|
|
2595
|
-
|
|
2622
|
+
uniqueId = new bson.ObjectId().toHexString();
|
|
2623
|
+
return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), uniqueId])];
|
|
2596
2624
|
case 2:
|
|
2597
2625
|
_a.sent();
|
|
2598
|
-
return [2 /*return
|
|
2626
|
+
return [2 /*return*/, uniqueId];
|
|
2599
2627
|
}
|
|
2600
2628
|
});
|
|
2601
2629
|
});
|
|
@@ -3166,7 +3194,7 @@
|
|
|
3166
3194
|
isFinished = progress.percent >= 100;
|
|
3167
3195
|
}
|
|
3168
3196
|
if (!!isFinished) return [3 /*break*/, 4];
|
|
3169
|
-
if (waitTime >=
|
|
3197
|
+
if (waitTime >= this.jobMan.maxTimeout) {
|
|
3170
3198
|
throw new Error("Progress with id: " + id + " probably never will be finished!");
|
|
3171
3199
|
}
|
|
3172
3200
|
return [4 /*yield*/, promiseTimeout(delay)];
|
|
@@ -5912,7 +5940,7 @@
|
|
|
5912
5940
|
new Parameter("mongoDb", "node-backend"),
|
|
5913
5941
|
new Parameter("mongoUser", null),
|
|
5914
5942
|
new Parameter("mongoPassword", null),
|
|
5915
|
-
new Parameter("nodeEnv", "
|
|
5943
|
+
new Parameter("nodeEnv", "production"),
|
|
5916
5944
|
new Parameter("appPort", 80),
|
|
5917
5945
|
new Parameter("zmqPort", 3000),
|
|
5918
5946
|
new Parameter("zmqBackPort", 3100),
|
|
@@ -5924,6 +5952,7 @@
|
|
|
5924
5952
|
new Parameter("idPrefix", "ID-"),
|
|
5925
5953
|
new Parameter("idParts", [4, 4]),
|
|
5926
5954
|
new Parameter("jsonLimit", "250mb"),
|
|
5955
|
+
new Parameter("jobTimeout", 5 * 60 * 1000),
|
|
5927
5956
|
new Parameter("cacheCollection", "cache"),
|
|
5928
5957
|
];
|
|
5929
5958
|
// Convert parameters to providers
|
|
@@ -5999,12 +6028,13 @@
|
|
|
5999
6028
|
});
|
|
6000
6029
|
restOptions = config.restOptions || {};
|
|
6001
6030
|
restOptions.defaultErrorHandler = false;
|
|
6002
|
-
restOptions.cors = {
|
|
6031
|
+
restOptions.cors = Object.assign({
|
|
6003
6032
|
credentials: true,
|
|
6033
|
+
exposedHeaders: ["content-disposition"],
|
|
6004
6034
|
origin: function (origin, callback) {
|
|
6005
6035
|
callback(null, true);
|
|
6006
6036
|
}
|
|
6007
|
-
};
|
|
6037
|
+
}, restOptions.cors || {});
|
|
6008
6038
|
restOptions.routePrefix = config.routePrefix || "/api";
|
|
6009
6039
|
restOptions.routePrefix = restOptions.routePrefix == "/" ? "" : restOptions.routePrefix;
|
|
6010
6040
|
restOptions.middlewares = [exports.ErrorHandlerMiddleware, ContainerMiddleware, exports.LanguageMiddleware, RequestStartedMiddleware, RequestEndedMiddleware]
|
|
@@ -6225,6 +6255,7 @@
|
|
|
6225
6255
|
exports.random = random;
|
|
6226
6256
|
exports.readAndDeleteFile = readAndDeleteFile;
|
|
6227
6257
|
exports.readFile = readFile;
|
|
6258
|
+
exports.regroup = regroup;
|
|
6228
6259
|
exports.runCommand = runCommand;
|
|
6229
6260
|
exports.setupBackend = setupBackend;
|
|
6230
6261
|
exports.streamToBuffer = streamToBuffer;
|