@stemy/backend 2.9.8 → 3.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/bundles/stemy-backend.umd.js +191 -201
- 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 +2 -0
- package/esm2015/common-types.js +1 -1
- package/esm2015/public_api.js +4 -16
- package/esm2015/rest-controllers/assets.controller.js +4 -2
- package/esm2015/services/entities/asset.js +17 -24
- package/esm2015/services/job-manager.js +50 -80
- package/esm2015/utils.js +68 -4
- package/fesm2015/stemy-backend.js +136 -120
- package/fesm2015/stemy-backend.js.map +1 -1
- package/package.json +2 -3
- package/public_api.d.ts +1 -1
- package/services/job-manager.d.ts +11 -13
- package/stemy-backend.metadata.json +1 -1
- package/utils.d.ts +35 -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-
|
|
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-
|
|
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-
|
|
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,
|
|
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('socket.io-client'), 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', 'socket.io-client', '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.socket["io-client"], 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, socket_io_client, 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 ioredis__default = /*#__PURE__*/_interopDefaultLegacy(ioredis);
|
|
32
31
|
var socket_io_client__default = /*#__PURE__*/_interopDefaultLegacy(socket_io_client);
|
|
33
32
|
var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
|
|
34
33
|
var socket_io__default = /*#__PURE__*/_interopDefaultLegacy(socket_io);
|
|
@@ -745,11 +744,16 @@
|
|
|
745
744
|
function valueToPromise(value) {
|
|
746
745
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
747
746
|
}
|
|
748
|
-
function promiseTimeout(timeout) {
|
|
747
|
+
function promiseTimeout(timeout, error) {
|
|
749
748
|
if (timeout === void 0) { timeout = 1000; }
|
|
750
|
-
|
|
749
|
+
if (error === void 0) { error = false; }
|
|
750
|
+
return new Promise(function (resolve, reject) {
|
|
751
751
|
setTimeout(function () {
|
|
752
|
-
|
|
752
|
+
if (error) {
|
|
753
|
+
reject("Timeout exceeded: " + timeout + "ms");
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
resolve("Timeout: " + timeout + "ms");
|
|
753
757
|
}, timeout);
|
|
754
758
|
});
|
|
755
759
|
}
|
|
@@ -1059,6 +1063,66 @@
|
|
|
1059
1063
|
console.error(data.toString());
|
|
1060
1064
|
});
|
|
1061
1065
|
});
|
|
1066
|
+
}
|
|
1067
|
+
exports.ConsoleColor = void 0;
|
|
1068
|
+
(function (ConsoleColor) {
|
|
1069
|
+
ConsoleColor["Reset"] = "\u001B[0m";
|
|
1070
|
+
ConsoleColor["Bright"] = "\u001B[1m";
|
|
1071
|
+
ConsoleColor["Dim"] = "\u001B[2m";
|
|
1072
|
+
ConsoleColor["Underscore"] = "\u001B[4m";
|
|
1073
|
+
ConsoleColor["Blink"] = "\u001B[5m";
|
|
1074
|
+
ConsoleColor["Reverse"] = "\u001B[7m";
|
|
1075
|
+
ConsoleColor["Hidden"] = "\u001B[8m";
|
|
1076
|
+
ConsoleColor["FgBlack"] = "\u001B[30m";
|
|
1077
|
+
ConsoleColor["FgRed"] = "\u001B[31m";
|
|
1078
|
+
ConsoleColor["FgGreen"] = "\u001B[32m";
|
|
1079
|
+
ConsoleColor["FgYellow"] = "\u001B[33m";
|
|
1080
|
+
ConsoleColor["FgBlue"] = "\u001B[34m";
|
|
1081
|
+
ConsoleColor["FgMagenta"] = "\u001B[35m";
|
|
1082
|
+
ConsoleColor["FgCyan"] = "\u001B[36m";
|
|
1083
|
+
ConsoleColor["FgWhite"] = "\u001B[37m";
|
|
1084
|
+
ConsoleColor["BgBlack"] = "\u001B[40m";
|
|
1085
|
+
ConsoleColor["BgRed"] = "\u001B[41m";
|
|
1086
|
+
ConsoleColor["BgGreen"] = "\u001B[42m";
|
|
1087
|
+
ConsoleColor["BgYellow"] = "\u001B[43m";
|
|
1088
|
+
ConsoleColor["BgBlue"] = "\u001B[44m";
|
|
1089
|
+
ConsoleColor["BgMagenta"] = "\u001B[45m";
|
|
1090
|
+
ConsoleColor["BgCyan"] = "\u001B[46m";
|
|
1091
|
+
ConsoleColor["BgWhite"] = "\u001B[47m";
|
|
1092
|
+
})(exports.ConsoleColor || (exports.ConsoleColor = {}));
|
|
1093
|
+
var defaultColors = {
|
|
1094
|
+
keyColor: exports.ConsoleColor.Dim,
|
|
1095
|
+
numberColor: exports.ConsoleColor.FgBlue,
|
|
1096
|
+
stringColor: exports.ConsoleColor.FgCyan,
|
|
1097
|
+
trueColor: exports.ConsoleColor.FgGreen,
|
|
1098
|
+
falseColor: exports.ConsoleColor.FgRed,
|
|
1099
|
+
nullColor: exports.ConsoleColor.BgMagenta
|
|
1100
|
+
};
|
|
1101
|
+
function jsonHighlight(input, colorOptions) {
|
|
1102
|
+
var colors = Object.assign({}, defaultColors, colorOptions);
|
|
1103
|
+
var json = (isString(input) ? input : JSON.stringify(input, null, 2)).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
1104
|
+
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g, function (match) {
|
|
1105
|
+
var color = colors.numberColor;
|
|
1106
|
+
if (/^"/.test(match)) {
|
|
1107
|
+
if (/:$/.test(match)) {
|
|
1108
|
+
color = colors.keyColor;
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
color = colors.stringColor;
|
|
1112
|
+
match = '"' + match.substr(1, match.length - 2) + '"';
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
color = /true/.test(match)
|
|
1117
|
+
? colors.trueColor
|
|
1118
|
+
: /false/.test(match)
|
|
1119
|
+
? colors.falseColor
|
|
1120
|
+
: /null/.test(match)
|
|
1121
|
+
? colors.nullColor
|
|
1122
|
+
: color;
|
|
1123
|
+
}
|
|
1124
|
+
return "" + color + match + exports.ConsoleColor.Reset;
|
|
1125
|
+
});
|
|
1062
1126
|
}
|
|
1063
1127
|
|
|
1064
1128
|
var __decorate$x = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -1606,15 +1670,16 @@
|
|
|
1606
1670
|
};
|
|
1607
1671
|
Asset.toImage = function (stream, meta, params) {
|
|
1608
1672
|
return __awaiter$s(this, void 0, void 0, function () {
|
|
1609
|
-
var crop, buffer, cropBefore, cropAfter,
|
|
1610
|
-
return __generator(this, function (
|
|
1611
|
-
switch (
|
|
1673
|
+
var crop, buffer, cropBefore, cropAfter, img, _a, width, height, canvasScaleX, canvasScaleY, _b, e_1;
|
|
1674
|
+
return __generator(this, function (_c) {
|
|
1675
|
+
switch (_c.label) {
|
|
1612
1676
|
case 0:
|
|
1613
1677
|
params = params || {};
|
|
1614
1678
|
crop = Asset.toCropRegion(meta.crop);
|
|
1615
|
-
// Return
|
|
1616
|
-
if (Object.keys(params).length == 0 && !crop)
|
|
1679
|
+
// Return the stream if there is no params and no default crop exists
|
|
1680
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.extension) === "svg" || (Object.keys(params).length == 0 && !crop)) {
|
|
1617
1681
|
return [2 /*return*/, stream];
|
|
1682
|
+
}
|
|
1618
1683
|
// Parse params
|
|
1619
1684
|
params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
|
|
1620
1685
|
params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
|
|
@@ -1624,76 +1689,59 @@
|
|
|
1624
1689
|
params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
|
|
1625
1690
|
return [4 /*yield*/, streamToBuffer(stream)];
|
|
1626
1691
|
case 1:
|
|
1627
|
-
buffer =
|
|
1628
|
-
|
|
1692
|
+
buffer = _c.sent();
|
|
1693
|
+
_c.label = 2;
|
|
1629
1694
|
case 2:
|
|
1630
|
-
|
|
1695
|
+
_c.trys.push([2, 7, , 8]);
|
|
1631
1696
|
cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
|
|
1632
1697
|
cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
|
|
1633
|
-
|
|
1698
|
+
img = sharp$2(buffer);
|
|
1699
|
+
return [4 /*yield*/, img.metadata()];
|
|
1634
1700
|
case 3:
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1701
|
+
_a = _c.sent(), width = _a.width, height = _a.height;
|
|
1702
|
+
// Crop before resize
|
|
1703
|
+
if (cropBefore) {
|
|
1704
|
+
width = cropBefore.width;
|
|
1705
|
+
height = cropBefore.height;
|
|
1706
|
+
img = img.extract(cropBefore);
|
|
1707
|
+
}
|
|
1708
|
+
else if (crop) {
|
|
1709
|
+
width = crop.width;
|
|
1710
|
+
height = crop.height;
|
|
1711
|
+
img = img.extract(crop);
|
|
1712
|
+
}
|
|
1713
|
+
canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
|
|
1714
|
+
canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
|
|
1715
|
+
if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
|
|
1716
|
+
width = Math.round(width * params.canvasScaleX);
|
|
1717
|
+
height = Math.round(height * params.canvasScaleY);
|
|
1718
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
|
|
1719
|
+
}
|
|
1720
|
+
// Resize image
|
|
1721
|
+
if (params.scaleX !== 1 || params.scaleY !== 1) {
|
|
1722
|
+
width = Math.round(width * params.scaleX);
|
|
1723
|
+
height = Math.round(height * params.scaleY);
|
|
1724
|
+
img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
|
|
1725
|
+
}
|
|
1726
|
+
// Crop after resize
|
|
1727
|
+
if (cropAfter) {
|
|
1728
|
+
img = img.extract(cropAfter);
|
|
1729
|
+
}
|
|
1730
|
+
if (!(params.rotation !== 0)) return [3 /*break*/, 5];
|
|
1731
|
+
return [4 /*yield*/, img.toBuffer()];
|
|
1642
1732
|
case 4:
|
|
1643
|
-
buffer =
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
return [3 /*break*/, 7];
|
|
1733
|
+
buffer = _c.sent();
|
|
1734
|
+
img = sharp$2(buffer).rotate(params.rotation);
|
|
1735
|
+
_c.label = 5;
|
|
1647
1736
|
case 5:
|
|
1648
|
-
|
|
1649
|
-
return [4 /*yield*/,
|
|
1650
|
-
|
|
1651
|
-
.toBuffer()];
|
|
1652
|
-
case 6:
|
|
1653
|
-
buffer = _a.sent();
|
|
1654
|
-
width = crop.width;
|
|
1655
|
-
height = crop.height;
|
|
1656
|
-
_a.label = 7;
|
|
1737
|
+
_b = bufferToStream;
|
|
1738
|
+
return [4 /*yield*/, img.toBuffer()];
|
|
1739
|
+
case 6: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
|
|
1657
1740
|
case 7:
|
|
1658
|
-
|
|
1659
|
-
width = Math.round(width * params.canvasScaleX);
|
|
1660
|
-
height = Math.round(height * params.canvasScaleY);
|
|
1661
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1662
|
-
.resize({ width: width, height: height, background: "#00000000", fit: "contain" })
|
|
1663
|
-
.toBuffer()];
|
|
1664
|
-
case 8:
|
|
1665
|
-
buffer = _a.sent();
|
|
1666
|
-
_a.label = 9;
|
|
1667
|
-
case 9:
|
|
1668
|
-
if (!(params.scaleX !== 1 || params.scaleY !== 1)) return [3 /*break*/, 11];
|
|
1669
|
-
width = Math.round(width * params.scaleX);
|
|
1670
|
-
height = Math.round(height * params.scaleY);
|
|
1671
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1672
|
-
.resize({ width: width, height: height, background: "#00000000", fit: "fill" })
|
|
1673
|
-
.toBuffer()];
|
|
1674
|
-
case 10:
|
|
1675
|
-
buffer = _a.sent();
|
|
1676
|
-
_a.label = 11;
|
|
1677
|
-
case 11:
|
|
1678
|
-
if (!cropAfter) return [3 /*break*/, 13];
|
|
1679
|
-
return [4 /*yield*/, sharp$2(buffer)
|
|
1680
|
-
.extract(cropAfter)
|
|
1681
|
-
.toBuffer()];
|
|
1682
|
-
case 12:
|
|
1683
|
-
buffer = _a.sent();
|
|
1684
|
-
_a.label = 13;
|
|
1685
|
-
case 13:
|
|
1686
|
-
if (!(params.rotation !== 0)) return [3 /*break*/, 15];
|
|
1687
|
-
return [4 /*yield*/, sharp$2(buffer).rotate(params.rotation).toBuffer()];
|
|
1688
|
-
case 14:
|
|
1689
|
-
buffer = _a.sent();
|
|
1690
|
-
_a.label = 15;
|
|
1691
|
-
case 15: return [2 /*return*/, bufferToStream(buffer)];
|
|
1692
|
-
case 16:
|
|
1693
|
-
e_1 = _a.sent();
|
|
1741
|
+
e_1 = _c.sent();
|
|
1694
1742
|
console.log("Asset image conversion error", e_1);
|
|
1695
1743
|
return [2 /*return*/, bufferToStream(buffer)];
|
|
1696
|
-
case
|
|
1744
|
+
case 8: return [2 /*return*/];
|
|
1697
1745
|
}
|
|
1698
1746
|
});
|
|
1699
1747
|
});
|
|
@@ -2330,7 +2378,6 @@
|
|
|
2330
2378
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2331
2379
|
});
|
|
2332
2380
|
};
|
|
2333
|
-
var IORedis = ioredis__default["default"];
|
|
2334
2381
|
exports.JobManager = /** @class */ (function () {
|
|
2335
2382
|
function JobManager(config, container, jobTypes) {
|
|
2336
2383
|
var _this = this;
|
|
@@ -2338,8 +2385,9 @@
|
|
|
2338
2385
|
this.container = container;
|
|
2339
2386
|
this.jobTypes = jobTypes || [];
|
|
2340
2387
|
this.jobs = this.jobTypes.reduce(function (res, jobType) {
|
|
2341
|
-
res[getConstructorName(jobType)] = {
|
|
2342
|
-
|
|
2388
|
+
res[getConstructorName(jobType)] = function (jobParams) {
|
|
2389
|
+
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2390
|
+
return job.process();
|
|
2343
2391
|
};
|
|
2344
2392
|
return res;
|
|
2345
2393
|
}, {});
|
|
@@ -2361,9 +2409,8 @@
|
|
|
2361
2409
|
});
|
|
2362
2410
|
});
|
|
2363
2411
|
};
|
|
2364
|
-
JobManager.prototype.enqueueWithName = function (name, params
|
|
2412
|
+
JobManager.prototype.enqueueWithName = function (name, params) {
|
|
2365
2413
|
if (params === void 0) { params = {}; }
|
|
2366
|
-
if (que === void 0) { que = "main"; }
|
|
2367
2414
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2368
2415
|
var jobName;
|
|
2369
2416
|
return __generator(this, function (_a) {
|
|
@@ -2371,35 +2418,13 @@
|
|
|
2371
2418
|
case 0: return [4 /*yield*/, this.tryResolveFromName(name, params)];
|
|
2372
2419
|
case 1:
|
|
2373
2420
|
jobName = _a.sent();
|
|
2374
|
-
return [
|
|
2375
|
-
case 2:
|
|
2376
|
-
_a.sent();
|
|
2377
|
-
return [2 /*return*/];
|
|
2378
|
-
}
|
|
2379
|
-
});
|
|
2380
|
-
});
|
|
2381
|
-
};
|
|
2382
|
-
JobManager.prototype.enqueue = function (jobType, params, que) {
|
|
2383
|
-
if (params === void 0) { params = {}; }
|
|
2384
|
-
if (que === void 0) { que = "main"; }
|
|
2385
|
-
return __awaiter$o(this, void 0, void 0, function () {
|
|
2386
|
-
var jobName;
|
|
2387
|
-
return __generator(this, function (_a) {
|
|
2388
|
-
switch (_a.label) {
|
|
2389
|
-
case 0: return [4 /*yield*/, this.tryResolveAndConnect(jobType, params)];
|
|
2390
|
-
case 1:
|
|
2391
|
-
jobName = _a.sent();
|
|
2392
|
-
return [4 /*yield*/, this.queue.enqueue(que, jobName, [params])];
|
|
2393
|
-
case 2:
|
|
2394
|
-
_a.sent();
|
|
2395
|
-
return [2 /*return*/];
|
|
2421
|
+
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2396
2422
|
}
|
|
2397
2423
|
});
|
|
2398
2424
|
});
|
|
2399
2425
|
};
|
|
2400
|
-
JobManager.prototype.
|
|
2426
|
+
JobManager.prototype.enqueue = function (jobType, params) {
|
|
2401
2427
|
if (params === void 0) { params = {}; }
|
|
2402
|
-
if (que === void 0) { que = "main"; }
|
|
2403
2428
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2404
2429
|
var jobName;
|
|
2405
2430
|
return __generator(this, function (_a) {
|
|
@@ -2407,25 +2432,20 @@
|
|
|
2407
2432
|
case 0: return [4 /*yield*/, this.tryResolveAndConnect(jobType, params)];
|
|
2408
2433
|
case 1:
|
|
2409
2434
|
jobName = _a.sent();
|
|
2410
|
-
return [
|
|
2411
|
-
case 2:
|
|
2412
|
-
_a.sent();
|
|
2413
|
-
return [2 /*return*/];
|
|
2435
|
+
return [2 /*return*/, this.sendToWorkers(jobName, params)];
|
|
2414
2436
|
}
|
|
2415
2437
|
});
|
|
2416
2438
|
});
|
|
2417
2439
|
};
|
|
2418
|
-
JobManager.prototype.
|
|
2419
|
-
if (params === void 0) { params = {}; }
|
|
2420
|
-
if (que === void 0) { que = "main"; }
|
|
2440
|
+
JobManager.prototype.sendToWorkers = function (jobName, params) {
|
|
2421
2441
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2422
|
-
var
|
|
2442
|
+
var publisher;
|
|
2423
2443
|
return __generator(this, function (_a) {
|
|
2424
2444
|
switch (_a.label) {
|
|
2425
|
-
case 0: return [4 /*yield*/, this.
|
|
2445
|
+
case 0: return [4 /*yield*/, this.scheduler];
|
|
2426
2446
|
case 1:
|
|
2427
|
-
|
|
2428
|
-
return [4 /*yield*/,
|
|
2447
|
+
publisher = _a.sent();
|
|
2448
|
+
return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
|
|
2429
2449
|
case 2:
|
|
2430
2450
|
_a.sent();
|
|
2431
2451
|
return [2 /*return*/];
|
|
@@ -2433,10 +2453,9 @@
|
|
|
2433
2453
|
});
|
|
2434
2454
|
});
|
|
2435
2455
|
};
|
|
2436
|
-
JobManager.prototype.schedule = function (minute, hour, dayOfMonth, month, dayOfWeek, jobType, params
|
|
2456
|
+
JobManager.prototype.schedule = function (minute, hour, dayOfMonth, month, dayOfWeek, jobType, params) {
|
|
2437
2457
|
var _this = this;
|
|
2438
2458
|
if (params === void 0) { params = {}; }
|
|
2439
|
-
if (que === void 0) { que = "main"; }
|
|
2440
2459
|
var expression = [minute, hour, dayOfMonth, month, dayOfWeek].map(function (t) {
|
|
2441
2460
|
if (isObject(t)) {
|
|
2442
2461
|
var range = t;
|
|
@@ -2453,33 +2472,53 @@
|
|
|
2453
2472
|
return null;
|
|
2454
2473
|
}
|
|
2455
2474
|
return nodeCron.schedule(expression, function () {
|
|
2456
|
-
_this.enqueue(jobType, params
|
|
2475
|
+
_this.enqueue(jobType, params).catch(function (e) {
|
|
2457
2476
|
console.log("Can't enqueue job: '" + jobName + "' because: " + e);
|
|
2458
2477
|
});
|
|
2459
2478
|
});
|
|
2460
2479
|
};
|
|
2461
2480
|
JobManager.prototype.startProcessing = function () {
|
|
2462
|
-
|
|
2481
|
+
var _this = this;
|
|
2482
|
+
var host = this.config.resolve("zmqRemoteHost");
|
|
2483
|
+
this.worker = zeromq.socket("pull");
|
|
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;
|
|
2463
2487
|
return __generator(this, function (_a) {
|
|
2464
2488
|
switch (_a.label) {
|
|
2465
2489
|
case 0:
|
|
2466
|
-
|
|
2467
|
-
|
|
2490
|
+
_a.trys.push([0, 5, , 6]);
|
|
2491
|
+
jobName = name.toString("utf8");
|
|
2492
|
+
jobParams = JSON.parse(args.toString("utf8"));
|
|
2493
|
+
timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
|
|
2494
|
+
jobNameLog = "\u001B[36m\"" + jobName + "\"\u001B[0m";
|
|
2495
|
+
jobArgsLog = "\n" + jsonHighlight(jobParams) + "\n";
|
|
2496
|
+
console.time(timerId);
|
|
2497
|
+
console.timeLog(timerId, "Started working on background job: " + jobNameLog + " with args: " + jobArgsLog);
|
|
2498
|
+
_a.label = 1;
|
|
2468
2499
|
case 1:
|
|
2469
|
-
_a.
|
|
2470
|
-
return [4 /*yield*/, this.
|
|
2500
|
+
_a.trys.push([1, 3, , 4]);
|
|
2501
|
+
return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(15000, true)])];
|
|
2471
2502
|
case 2:
|
|
2472
2503
|
_a.sent();
|
|
2473
|
-
|
|
2504
|
+
console.timeLog(timerId, "Finished working on background job: " + jobNameLog + " with args: " + jobArgsLog);
|
|
2505
|
+
return [3 /*break*/, 4];
|
|
2474
2506
|
case 3:
|
|
2475
|
-
_a.sent();
|
|
2476
|
-
|
|
2507
|
+
e_1 = _a.sent();
|
|
2508
|
+
console.timeLog(timerId, "Background job failed: " + jobNameLog + " with args: " + jobArgsLog + e_1.message + "\n\n");
|
|
2509
|
+
return [3 /*break*/, 4];
|
|
2477
2510
|
case 4:
|
|
2478
|
-
|
|
2479
|
-
return [
|
|
2511
|
+
console.timeEnd(timerId);
|
|
2512
|
+
return [3 /*break*/, 6];
|
|
2513
|
+
case 5:
|
|
2514
|
+
e_2 = _a.sent();
|
|
2515
|
+
console.log("Failed to start job: " + e_2.message);
|
|
2516
|
+
return [3 /*break*/, 6];
|
|
2517
|
+
case 6: return [2 /*return*/];
|
|
2480
2518
|
}
|
|
2481
2519
|
});
|
|
2482
|
-
});
|
|
2520
|
+
}); });
|
|
2521
|
+
console.log("Waiting for jobs at: " + host);
|
|
2483
2522
|
};
|
|
2484
2523
|
JobManager.prototype.tryResolve = function (jobType, params) {
|
|
2485
2524
|
var jobName = getConstructorName(jobType);
|
|
@@ -2494,47 +2533,6 @@
|
|
|
2494
2533
|
}
|
|
2495
2534
|
return jobName;
|
|
2496
2535
|
};
|
|
2497
|
-
JobManager.prototype.initialize = function () {
|
|
2498
|
-
if (this.queue)
|
|
2499
|
-
return;
|
|
2500
|
-
var config = this.config;
|
|
2501
|
-
var options = { password: config.resolve("redisPassword") };
|
|
2502
|
-
var sentinels = config.resolve("redisSentinels");
|
|
2503
|
-
var redis = !sentinels
|
|
2504
|
-
? null
|
|
2505
|
-
: new IORedis({
|
|
2506
|
-
sentinels: sentinels,
|
|
2507
|
-
name: config.resolve("redisCluster"),
|
|
2508
|
-
});
|
|
2509
|
-
var connection = {
|
|
2510
|
-
pkg: "ioredis",
|
|
2511
|
-
host: config.resolve("redisHost"),
|
|
2512
|
-
password: options.password,
|
|
2513
|
-
port: config.resolve("redisPort"),
|
|
2514
|
-
namespace: config.resolve("redisNamespace"),
|
|
2515
|
-
redis: redis,
|
|
2516
|
-
options: options
|
|
2517
|
-
};
|
|
2518
|
-
var queues = config.resolve("workQueues");
|
|
2519
|
-
this.queue = new nodeResque.Queue({ connection: connection }, this.jobs);
|
|
2520
|
-
this.worker = new nodeResque.Worker({ connection: connection, queues: queues }, this.jobs);
|
|
2521
|
-
this.worker.on("job", function (queue, job) {
|
|
2522
|
-
console.log("working job " + queue + " " + JSON.stringify(job));
|
|
2523
|
-
});
|
|
2524
|
-
this.worker.on("reEnqueue", function (queue, job, plugin) {
|
|
2525
|
-
console.log("reEnqueue job (" + plugin + ") " + queue + " " + JSON.stringify(job));
|
|
2526
|
-
});
|
|
2527
|
-
this.worker.on("success", function (queue, job, result, duration) {
|
|
2528
|
-
console.log("job success " + queue + " " + JSON.stringify(job) + " >> " + result + " (" + duration + "ms)");
|
|
2529
|
-
});
|
|
2530
|
-
this.worker.on("failure", function (queue, job, failure, duration) {
|
|
2531
|
-
console.log("job failure " + queue + " " + JSON.stringify(job) + " >> " + failure + " (" + duration + "ms)");
|
|
2532
|
-
});
|
|
2533
|
-
this.worker.on("error", function (error, queue, job) {
|
|
2534
|
-
console.log("error " + queue + " " + JSON.stringify(job) + " >> " + error);
|
|
2535
|
-
});
|
|
2536
|
-
this.scheduler = new nodeResque.Scheduler({ connection: connection }, this.jobs);
|
|
2537
|
-
};
|
|
2538
2536
|
JobManager.prototype.tryResolveFromName = function (jobName, params) {
|
|
2539
2537
|
var jobType = this.jobTypes.find(function (type) {
|
|
2540
2538
|
return getConstructorName(type) == jobName;
|
|
@@ -2546,17 +2544,25 @@
|
|
|
2546
2544
|
};
|
|
2547
2545
|
JobManager.prototype.tryResolveAndConnect = function (jobType, params) {
|
|
2548
2546
|
return __awaiter$o(this, void 0, void 0, function () {
|
|
2549
|
-
var
|
|
2547
|
+
var _this = this;
|
|
2550
2548
|
return __generator(this, function (_a) {
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2549
|
+
this.scheduler = this.scheduler || new Promise(function (resolve) { return __awaiter$o(_this, void 0, void 0, function () {
|
|
2550
|
+
var port, publisher;
|
|
2551
|
+
return __generator(this, function (_a) {
|
|
2552
|
+
switch (_a.label) {
|
|
2553
|
+
case 0:
|
|
2554
|
+
port = this.config.resolve("zmqPort");
|
|
2555
|
+
publisher = zeromq.socket("push");
|
|
2556
|
+
return [4 /*yield*/, publisher.bind("tcp://0.0.0.0:" + port)];
|
|
2557
|
+
case 1:
|
|
2558
|
+
_a.sent();
|
|
2559
|
+
console.log("Publisher bound to port: " + port);
|
|
2560
|
+
resolve(publisher);
|
|
2561
|
+
return [2 /*return*/];
|
|
2562
|
+
}
|
|
2563
|
+
});
|
|
2564
|
+
}); });
|
|
2565
|
+
return [2 /*return*/, this.tryResolve(jobType, params)];
|
|
2560
2566
|
});
|
|
2561
2567
|
});
|
|
2562
2568
|
};
|
|
@@ -2568,13 +2574,6 @@
|
|
|
2568
2574
|
container.register(jobType, jobType);
|
|
2569
2575
|
return container.resolve(jobType);
|
|
2570
2576
|
};
|
|
2571
|
-
JobManager.prototype.toPerformFunction = function (jobType) {
|
|
2572
|
-
var _this = this;
|
|
2573
|
-
return function (jobParams) {
|
|
2574
|
-
var job = _this.resolveJobInstance(jobType, jobParams);
|
|
2575
|
-
return job.process();
|
|
2576
|
-
};
|
|
2577
|
-
};
|
|
2578
2577
|
return JobManager;
|
|
2579
2578
|
}());
|
|
2580
2579
|
exports.JobManager = __decorate$s([
|
|
@@ -4729,7 +4728,9 @@
|
|
|
4729
4728
|
case 0: return [4 /*yield*/, this.getAsset("Image", id, params.lazy, res)];
|
|
4730
4729
|
case 1:
|
|
4731
4730
|
asset = _c.sent();
|
|
4732
|
-
|
|
4731
|
+
if (rotation !== 0) {
|
|
4732
|
+
params.rotation = params.rotation || rotation;
|
|
4733
|
+
}
|
|
4733
4734
|
return [2 /*return*/, asset.downloadImage(params)];
|
|
4734
4735
|
}
|
|
4735
4736
|
});
|
|
@@ -5833,20 +5834,8 @@
|
|
|
5833
5834
|
new Parameter("mongoPassword", null),
|
|
5834
5835
|
new Parameter("nodeEnv", "development"),
|
|
5835
5836
|
new Parameter("appPort", 80),
|
|
5836
|
-
new Parameter("
|
|
5837
|
-
new Parameter("
|
|
5838
|
-
new Parameter("redisPassword", "123456"),
|
|
5839
|
-
new Parameter("redisNamespace", "resque"),
|
|
5840
|
-
new Parameter("redisCluster", "mymaster"),
|
|
5841
|
-
new Parameter("redisSentinels", null, function (value) {
|
|
5842
|
-
if (!value)
|
|
5843
|
-
return null;
|
|
5844
|
-
return value.split(", ").map(function (item) {
|
|
5845
|
-
var values = item.split(":");
|
|
5846
|
-
return { host: values[0], port: Number(values[1]) };
|
|
5847
|
-
});
|
|
5848
|
-
}),
|
|
5849
|
-
new Parameter("workQueues", ["main"]),
|
|
5837
|
+
new Parameter("zmqPort", 3000),
|
|
5838
|
+
new Parameter("zmqRemoteHost", "tcp://127.0.0.1:3000"),
|
|
5850
5839
|
new Parameter("isWorker", false),
|
|
5851
5840
|
new Parameter("mainEndpoint", ""),
|
|
5852
5841
|
new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
@@ -6135,6 +6124,7 @@
|
|
|
6135
6124
|
exports.isPrimitive = isPrimitive;
|
|
6136
6125
|
exports.isString = isString;
|
|
6137
6126
|
exports.isType = isType;
|
|
6127
|
+
exports.jsonHighlight = jsonHighlight;
|
|
6138
6128
|
exports.lastItem = lastItem;
|
|
6139
6129
|
exports.lcFirst = lcFirst;
|
|
6140
6130
|
exports.lookupPipelines = lookupPipelines;
|