@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
|
@@ -25,7 +25,7 @@ import { GridFSBucket } from 'mongodb';
|
|
|
25
25
|
import dotenv from 'dotenv';
|
|
26
26
|
import { validate, schedule } from 'node-cron';
|
|
27
27
|
import { socket } from 'zeromq';
|
|
28
|
-
import
|
|
28
|
+
import { filter as filter$1, map } from 'rxjs/operators';
|
|
29
29
|
import { createServer } from 'http';
|
|
30
30
|
import express_, { static as static$1 } from 'express';
|
|
31
31
|
import socket_io from 'socket.io';
|
|
@@ -661,6 +661,7 @@ var ConsoleColor;
|
|
|
661
661
|
ConsoleColor["FgMagenta"] = "\u001B[35m";
|
|
662
662
|
ConsoleColor["FgCyan"] = "\u001B[36m";
|
|
663
663
|
ConsoleColor["FgWhite"] = "\u001B[37m";
|
|
664
|
+
ConsoleColor["FgDefault"] = "\u001B[38m";
|
|
664
665
|
ConsoleColor["BgBlack"] = "\u001B[40m";
|
|
665
666
|
ConsoleColor["BgRed"] = "\u001B[41m";
|
|
666
667
|
ConsoleColor["BgGreen"] = "\u001B[42m";
|
|
@@ -669,15 +670,20 @@ var ConsoleColor;
|
|
|
669
670
|
ConsoleColor["BgMagenta"] = "\u001B[45m";
|
|
670
671
|
ConsoleColor["BgCyan"] = "\u001B[46m";
|
|
671
672
|
ConsoleColor["BgWhite"] = "\u001B[47m";
|
|
673
|
+
ConsoleColor["BgDefault"] = "\u001B[48m";
|
|
672
674
|
})(ConsoleColor || (ConsoleColor = {}));
|
|
673
675
|
const defaultColors = {
|
|
674
|
-
keyColor: ConsoleColor.
|
|
676
|
+
keyColor: ConsoleColor.FgWhite,
|
|
675
677
|
numberColor: ConsoleColor.FgBlue,
|
|
676
|
-
stringColor: ConsoleColor.
|
|
678
|
+
stringColor: ConsoleColor.FgYellow,
|
|
677
679
|
trueColor: ConsoleColor.FgGreen,
|
|
678
680
|
falseColor: ConsoleColor.FgRed,
|
|
679
681
|
nullColor: ConsoleColor.BgMagenta
|
|
680
682
|
};
|
|
683
|
+
const MAX_TIMEOUT = 120000;
|
|
684
|
+
function colorize(input, color) {
|
|
685
|
+
return `${color}${input}${ConsoleColor.Reset}`;
|
|
686
|
+
}
|
|
681
687
|
function jsonHighlight(input, colorOptions) {
|
|
682
688
|
const colors = Object.assign({}, defaultColors, colorOptions);
|
|
683
689
|
const json = (isString(input) ? input : JSON.stringify(input, null, 2)).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
@@ -1457,11 +1463,10 @@ var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
1457
1463
|
});
|
|
1458
1464
|
};
|
|
1459
1465
|
class LazyAsset extends BaseEntity {
|
|
1460
|
-
constructor(id, data, collection, assets, progresses
|
|
1466
|
+
constructor(id, data, collection, assets, progresses) {
|
|
1461
1467
|
super(id, data, collection);
|
|
1462
1468
|
this.assets = assets;
|
|
1463
1469
|
this.progresses = progresses;
|
|
1464
|
-
this.jobMan = jobMan;
|
|
1465
1470
|
}
|
|
1466
1471
|
get jobName() {
|
|
1467
1472
|
return this.data.jobName;
|
|
@@ -1494,7 +1499,7 @@ class LazyAsset extends BaseEntity {
|
|
|
1494
1499
|
this.progresses.get(this.progressId).then(p => {
|
|
1495
1500
|
p === null || p === void 0 ? void 0 : p.cancel();
|
|
1496
1501
|
});
|
|
1497
|
-
this.startWorkingOnAsset().then(() => {
|
|
1502
|
+
this.startWorkingOnAsset(false).then(() => {
|
|
1498
1503
|
console.log(`Started working on lazy asset: ${this.id}`);
|
|
1499
1504
|
}).catch(reason => {
|
|
1500
1505
|
console.log(`Can't start working on lazy asset: ${this.id}\nReason: ${reason}`);
|
|
@@ -1513,7 +1518,7 @@ class LazyAsset extends BaseEntity {
|
|
|
1513
1518
|
yield this.progresses.waitToFinish(this.progressId);
|
|
1514
1519
|
return this.loadAsset();
|
|
1515
1520
|
}
|
|
1516
|
-
yield this.startWorkingOnAsset();
|
|
1521
|
+
yield this.startWorkingOnAsset(true);
|
|
1517
1522
|
return this.loadAsset();
|
|
1518
1523
|
});
|
|
1519
1524
|
}
|
|
@@ -1524,12 +1529,12 @@ class LazyAsset extends BaseEntity {
|
|
|
1524
1529
|
return asset;
|
|
1525
1530
|
});
|
|
1526
1531
|
}
|
|
1527
|
-
startWorkingOnAsset() {
|
|
1532
|
+
startWorkingOnAsset(fromLoad) {
|
|
1528
1533
|
return __awaiter$p(this, void 0, void 0, function* () {
|
|
1529
1534
|
this.data.progressId = (yield this.progresses.create()).id;
|
|
1530
1535
|
this.data.assetId = null;
|
|
1531
1536
|
yield this.save();
|
|
1532
|
-
yield this.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id }));
|
|
1537
|
+
yield this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id, fromLoad }));
|
|
1533
1538
|
});
|
|
1534
1539
|
}
|
|
1535
1540
|
}
|
|
@@ -1563,10 +1568,22 @@ let JobManager = class JobManager {
|
|
|
1563
1568
|
this.jobs = this.jobTypes.reduce((res, jobType) => {
|
|
1564
1569
|
res[getConstructorName(jobType)] = (jobParams) => {
|
|
1565
1570
|
const job = this.resolveJobInstance(jobType, jobParams);
|
|
1566
|
-
return job.process();
|
|
1571
|
+
return job.process(this.messageBridge);
|
|
1567
1572
|
};
|
|
1568
1573
|
return res;
|
|
1569
1574
|
}, {});
|
|
1575
|
+
this.messages = new Subject();
|
|
1576
|
+
this.messageBridge = {
|
|
1577
|
+
sendMessage: (message, params) => {
|
|
1578
|
+
this.workerPush.send([message, JSON.stringify(params)]);
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
this.processing = false;
|
|
1582
|
+
}
|
|
1583
|
+
on(message, cb) {
|
|
1584
|
+
return this.messages
|
|
1585
|
+
.pipe(filter$1(t => t.message === message))
|
|
1586
|
+
.pipe(map(t => t.params)).subscribe(cb);
|
|
1570
1587
|
}
|
|
1571
1588
|
process(jobType, params = {}) {
|
|
1572
1589
|
return __awaiter$o(this, void 0, void 0, function* () {
|
|
@@ -1583,20 +1600,12 @@ let JobManager = class JobManager {
|
|
|
1583
1600
|
}
|
|
1584
1601
|
enqueueWithName(name, params = {}) {
|
|
1585
1602
|
return __awaiter$o(this, void 0, void 0, function* () {
|
|
1586
|
-
|
|
1587
|
-
return this.sendToWorkers(jobName, params);
|
|
1603
|
+
return this.sendToWorkers(this.tryResolveFromName(name, params), params);
|
|
1588
1604
|
});
|
|
1589
1605
|
}
|
|
1590
1606
|
enqueue(jobType, params = {}) {
|
|
1591
1607
|
return __awaiter$o(this, void 0, void 0, function* () {
|
|
1592
|
-
|
|
1593
|
-
return this.sendToWorkers(jobName, params);
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
sendToWorkers(jobName, params) {
|
|
1597
|
-
return __awaiter$o(this, void 0, void 0, function* () {
|
|
1598
|
-
const publisher = yield this.scheduler;
|
|
1599
|
-
yield publisher.send([jobName, JSON.stringify(params), new ObjectId().toHexString()]);
|
|
1608
|
+
return this.sendToWorkers(this.tryResolveAndInit(jobType, params), params);
|
|
1600
1609
|
});
|
|
1601
1610
|
}
|
|
1602
1611
|
schedule(minute, hour, dayOfMonth, month, dayOfWeek, jobType, params = {}) {
|
|
@@ -1622,32 +1631,45 @@ let JobManager = class JobManager {
|
|
|
1622
1631
|
});
|
|
1623
1632
|
}
|
|
1624
1633
|
startProcessing() {
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1634
|
+
return __awaiter$o(this, void 0, void 0, function* () {
|
|
1635
|
+
if (this.processing)
|
|
1636
|
+
return null;
|
|
1637
|
+
this.processing = true;
|
|
1638
|
+
if (!this.config.resolve("isWorker")) {
|
|
1639
|
+
console.log(colorize(`Processing can not be started because this is NOT a worker process!`, ConsoleColor.FgRed));
|
|
1640
|
+
return null;
|
|
1641
|
+
}
|
|
1642
|
+
const host = this.config.resolve("zmqRemoteHost");
|
|
1643
|
+
const pushHost = `${host}:${this.config.resolve("zmqBackPort")}`;
|
|
1644
|
+
this.workerPush = socket("push");
|
|
1645
|
+
yield this.workerPush.connect(pushHost);
|
|
1646
|
+
console.log(`Worker producer connected to: ${pushHost}`);
|
|
1647
|
+
const pullHost = `${host}:${this.config.resolve("zmqPort")}`;
|
|
1648
|
+
this.workerPull = socket("pull");
|
|
1649
|
+
yield this.workerPull.connect(pullHost);
|
|
1650
|
+
console.log(`Worker consumer connected to: ${pullHost}`);
|
|
1651
|
+
this.workerPull.on("message", (name, args, uniqueId) => __awaiter$o(this, void 0, void 0, function* () {
|
|
1637
1652
|
try {
|
|
1638
|
-
|
|
1639
|
-
|
|
1653
|
+
const jobName = name.toString("utf8");
|
|
1654
|
+
const jobParams = JSON.parse(args.toString("utf8"));
|
|
1655
|
+
const timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
|
|
1656
|
+
console.time(timerId);
|
|
1657
|
+
console.timeLog(timerId, `Started working on background job: ${colorize(jobName, ConsoleColor.FgCyan)} with args: \n${jsonHighlight(jobParams)}\n\n`);
|
|
1658
|
+
this.messageBridge.sendMessage(`job-started`, { name: jobName });
|
|
1659
|
+
try {
|
|
1660
|
+
yield Promise.race([this.jobs[jobName](jobParams), promiseTimeout(MAX_TIMEOUT, true)]);
|
|
1661
|
+
console.timeLog(timerId, `Finished working on background job: ${colorize(jobName, ConsoleColor.FgCyan)}\n\n`);
|
|
1662
|
+
}
|
|
1663
|
+
catch (e) {
|
|
1664
|
+
console.timeLog(timerId, `Background job failed: ${colorize(jobName, ConsoleColor.FgRed)}\n${e}\n\n`);
|
|
1665
|
+
}
|
|
1666
|
+
console.timeEnd(timerId);
|
|
1640
1667
|
}
|
|
1641
1668
|
catch (e) {
|
|
1642
|
-
console.
|
|
1669
|
+
console.log(`Failed to start job: ${e.message}`);
|
|
1643
1670
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
catch (e) {
|
|
1647
|
-
console.log(`Failed to start job: ${e.message}`);
|
|
1648
|
-
}
|
|
1649
|
-
}));
|
|
1650
|
-
console.log(`Waiting for jobs at: ${host}`);
|
|
1671
|
+
}));
|
|
1672
|
+
});
|
|
1651
1673
|
}
|
|
1652
1674
|
tryResolve(jobType, params) {
|
|
1653
1675
|
const jobName = getConstructorName(jobType);
|
|
@@ -1669,19 +1691,28 @@ let JobManager = class JobManager {
|
|
|
1669
1691
|
if (!jobType) {
|
|
1670
1692
|
throw `Can't find job type with name: ${jobName} so it can't be enqueued!`;
|
|
1671
1693
|
}
|
|
1672
|
-
return this.
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1694
|
+
return this.tryResolveAndInit(jobType, params);
|
|
1695
|
+
}
|
|
1696
|
+
tryResolveAndInit(jobType, params) {
|
|
1697
|
+
if (!this.apiPush) {
|
|
1698
|
+
const port = this.config.resolve("zmqPort");
|
|
1699
|
+
this.apiPush = socket("push");
|
|
1700
|
+
this.apiPush.bind(`tcp://0.0.0.0:${port}`);
|
|
1701
|
+
console.log(`API producer bound to port: ${port}`);
|
|
1702
|
+
}
|
|
1703
|
+
if (!this.apiPull) {
|
|
1704
|
+
const backPort = this.config.resolve("zmqBackPort");
|
|
1705
|
+
this.apiPull = socket("pull");
|
|
1706
|
+
this.apiPull.bind(`tcp://0.0.0.0:${backPort}`);
|
|
1707
|
+
this.apiPull.on("message", (name, args) => {
|
|
1708
|
+
const message = name.toString("utf8");
|
|
1709
|
+
const params = JSON.parse((args === null || args === void 0 ? void 0 : args.toString("utf8")) || "{}");
|
|
1710
|
+
console.log(`Received a message from worker: "${colorize(message, ConsoleColor.FgCyan)}" with args: ${jsonHighlight(params)}\n\n`);
|
|
1711
|
+
this.messages.next({ message, params });
|
|
1712
|
+
});
|
|
1713
|
+
console.log(`API consumer bound to port: ${backPort}`);
|
|
1714
|
+
}
|
|
1715
|
+
return this.tryResolve(jobType, params);
|
|
1685
1716
|
}
|
|
1686
1717
|
resolveJobInstance(jobType, params) {
|
|
1687
1718
|
const container = this.container.createChildContainer();
|
|
@@ -1691,6 +1722,12 @@ let JobManager = class JobManager {
|
|
|
1691
1722
|
container.register(jobType, jobType);
|
|
1692
1723
|
return container.resolve(jobType);
|
|
1693
1724
|
}
|
|
1725
|
+
sendToWorkers(jobName, params) {
|
|
1726
|
+
return __awaiter$o(this, void 0, void 0, function* () {
|
|
1727
|
+
const publisher = yield this.apiPush;
|
|
1728
|
+
yield publisher.send([jobName, JSON.stringify(params), new ObjectId().toHexString()]);
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1694
1731
|
};
|
|
1695
1732
|
JobManager = __decorate$s([
|
|
1696
1733
|
injectable(),
|
|
@@ -1709,9 +1746,8 @@ var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
1709
1746
|
});
|
|
1710
1747
|
};
|
|
1711
1748
|
class Progress extends BaseEntity {
|
|
1712
|
-
constructor(id, data, collection
|
|
1749
|
+
constructor(id, data, collection) {
|
|
1713
1750
|
super(id, data, collection);
|
|
1714
|
-
this.client = client;
|
|
1715
1751
|
}
|
|
1716
1752
|
get current() {
|
|
1717
1753
|
return this.data.current;
|
|
@@ -1734,6 +1770,10 @@ class Progress extends BaseEntity {
|
|
|
1734
1770
|
get remaining() {
|
|
1735
1771
|
return this.max > 0 ? this.max - this.current : 0;
|
|
1736
1772
|
}
|
|
1773
|
+
setMessageBridge(messageBridge) {
|
|
1774
|
+
this.messageBridge = messageBridge || this.messageBridge;
|
|
1775
|
+
return this;
|
|
1776
|
+
}
|
|
1737
1777
|
createSubProgress(progressValue, max, message) {
|
|
1738
1778
|
return __awaiter$n(this, void 0, void 0, function* () {
|
|
1739
1779
|
if (max <= 0 && progressValue > 0) {
|
|
@@ -1777,9 +1817,6 @@ class Progress extends BaseEntity {
|
|
|
1777
1817
|
return null;
|
|
1778
1818
|
this.data.current = Math.min(this.max, this.current + value);
|
|
1779
1819
|
yield this.save();
|
|
1780
|
-
if (!this.client)
|
|
1781
|
-
return;
|
|
1782
|
-
this.client.emit("background-progress", this.id);
|
|
1783
1820
|
});
|
|
1784
1821
|
}
|
|
1785
1822
|
cancel() {
|
|
@@ -1788,6 +1825,12 @@ class Progress extends BaseEntity {
|
|
|
1788
1825
|
yield this.save();
|
|
1789
1826
|
});
|
|
1790
1827
|
}
|
|
1828
|
+
save() {
|
|
1829
|
+
if (this.messageBridge) {
|
|
1830
|
+
this.messageBridge.sendMessage(`progress-changed`, this.toJSON());
|
|
1831
|
+
}
|
|
1832
|
+
return super.save();
|
|
1833
|
+
}
|
|
1791
1834
|
}
|
|
1792
1835
|
class SubProgress {
|
|
1793
1836
|
constructor(parent, progressFrom, progressValue, mMax = 100) {
|
|
@@ -1827,6 +1870,12 @@ class SubProgress {
|
|
|
1827
1870
|
get canceled() {
|
|
1828
1871
|
return !this.parent || this.parent.canceled;
|
|
1829
1872
|
}
|
|
1873
|
+
setMessageBridge(messageBridge) {
|
|
1874
|
+
if (!this.parent)
|
|
1875
|
+
return this;
|
|
1876
|
+
this.parent.setMessageBridge(messageBridge);
|
|
1877
|
+
return this;
|
|
1878
|
+
}
|
|
1830
1879
|
createSubProgress(progressValue, max, message) {
|
|
1831
1880
|
return __awaiter$n(this, void 0, void 0, function* () {
|
|
1832
1881
|
if (max <= 0 && progressValue > 0) {
|
|
@@ -1915,33 +1964,34 @@ var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P,
|
|
|
1915
1964
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1916
1965
|
});
|
|
1917
1966
|
};
|
|
1918
|
-
const socketIOClient = socket_io_client;
|
|
1919
1967
|
let Progresses = class Progresses {
|
|
1920
|
-
constructor(connector,
|
|
1968
|
+
constructor(connector, jobMan) {
|
|
1921
1969
|
this.connector = connector;
|
|
1922
|
-
this.
|
|
1923
|
-
const mainEndpoint = this.config.resolve("mainEndpoint");
|
|
1924
|
-
this.client = !mainEndpoint ? null : socketIOClient(mainEndpoint, { path: "/socket" });
|
|
1970
|
+
this.jobMan = jobMan;
|
|
1925
1971
|
this.collection = connector.database.collection("progresses");
|
|
1972
|
+
this.progresses = {};
|
|
1973
|
+
this.jobMan.on("progress-changed", progress => {
|
|
1974
|
+
const id = progress.id;
|
|
1975
|
+
this.progresses[id] = new Progress(new ObjectId(id), progress, this.collection);
|
|
1976
|
+
});
|
|
1926
1977
|
}
|
|
1927
1978
|
waitToFinish(id) {
|
|
1928
1979
|
return __awaiter$m(this, void 0, void 0, function* () {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1944
|
-
return progress;
|
|
1980
|
+
return Promise.race([
|
|
1981
|
+
this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
|
|
1982
|
+
let progress = this.progresses[id];
|
|
1983
|
+
if (!progress || progress.percent < 100) {
|
|
1984
|
+
progress = yield this.get(id);
|
|
1985
|
+
}
|
|
1986
|
+
if (!progress) {
|
|
1987
|
+
throw new Error(`Progress does not exists with id: ${id}`);
|
|
1988
|
+
}
|
|
1989
|
+
return progress;
|
|
1990
|
+
}), 500),
|
|
1991
|
+
this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
|
|
1992
|
+
return this.progresses[id] || null;
|
|
1993
|
+
}), 25)
|
|
1994
|
+
]);
|
|
1945
1995
|
});
|
|
1946
1996
|
}
|
|
1947
1997
|
get(id) {
|
|
@@ -1952,13 +2002,13 @@ let Progresses = class Progresses {
|
|
|
1952
2002
|
find(where) {
|
|
1953
2003
|
return __awaiter$m(this, void 0, void 0, function* () {
|
|
1954
2004
|
const data = yield this.collection.findOne(where);
|
|
1955
|
-
return !data ? null : new Progress(data._id, data, this.collection
|
|
2005
|
+
return !data ? null : new Progress(data._id, data, this.collection);
|
|
1956
2006
|
});
|
|
1957
2007
|
}
|
|
1958
2008
|
create(max = 100) {
|
|
1959
2009
|
return __awaiter$m(this, void 0, void 0, function* () {
|
|
1960
2010
|
if (isNaN(max) || max <= 0) {
|
|
1961
|
-
throw
|
|
2011
|
+
throw new Error(`Max progress value must be bigger than zero`);
|
|
1962
2012
|
}
|
|
1963
2013
|
const data = {
|
|
1964
2014
|
current: 0,
|
|
@@ -1968,7 +2018,7 @@ let Progresses = class Progresses {
|
|
|
1968
2018
|
canceled: false
|
|
1969
2019
|
};
|
|
1970
2020
|
const res = yield this.collection.insertOne(data);
|
|
1971
|
-
return new Progress(res.insertedId, data, this.collection
|
|
2021
|
+
return new Progress(res.insertedId, data, this.collection);
|
|
1972
2022
|
});
|
|
1973
2023
|
}
|
|
1974
2024
|
remove(id) {
|
|
@@ -1977,11 +2027,35 @@ let Progresses = class Progresses {
|
|
|
1977
2027
|
return id;
|
|
1978
2028
|
});
|
|
1979
2029
|
}
|
|
2030
|
+
waitForProgress(id, cb, delay) {
|
|
2031
|
+
return __awaiter$m(this, void 0, void 0, function* () {
|
|
2032
|
+
let isFinished = false;
|
|
2033
|
+
let progress = null;
|
|
2034
|
+
let waitTime = 0;
|
|
2035
|
+
while (!isFinished) {
|
|
2036
|
+
progress = yield cb();
|
|
2037
|
+
waitTime += delay;
|
|
2038
|
+
if (progress) {
|
|
2039
|
+
if (progress.error) {
|
|
2040
|
+
throw new Error(progress.error);
|
|
2041
|
+
}
|
|
2042
|
+
isFinished = progress.percent >= 100;
|
|
2043
|
+
}
|
|
2044
|
+
if (!isFinished) {
|
|
2045
|
+
if (waitTime >= MAX_TIMEOUT) {
|
|
2046
|
+
throw new Error(`Progress with id: ${id} probably never will be finished!`);
|
|
2047
|
+
}
|
|
2048
|
+
yield promiseTimeout(delay);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return progress;
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
1980
2054
|
};
|
|
1981
2055
|
Progresses = __decorate$r([
|
|
1982
2056
|
injectable(),
|
|
1983
2057
|
singleton(),
|
|
1984
|
-
__metadata$l("design:paramtypes", [MongoConnector,
|
|
2058
|
+
__metadata$l("design:paramtypes", [MongoConnector, JobManager])
|
|
1985
2059
|
], Progresses);
|
|
1986
2060
|
|
|
1987
2061
|
var __decorate$q = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -2022,7 +2096,7 @@ let LazyAssets = class LazyAssets {
|
|
|
2022
2096
|
if (existingAsset)
|
|
2023
2097
|
return existingAsset;
|
|
2024
2098
|
const res = yield this.collection.insertOne(data);
|
|
2025
|
-
return new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses
|
|
2099
|
+
return new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses);
|
|
2026
2100
|
});
|
|
2027
2101
|
}
|
|
2028
2102
|
read(id) {
|
|
@@ -2035,7 +2109,7 @@ let LazyAssets = class LazyAssets {
|
|
|
2035
2109
|
const data = yield this.collection.findOne(where);
|
|
2036
2110
|
return !data
|
|
2037
2111
|
? null
|
|
2038
|
-
: new LazyAsset(data._id, data, this.collection, this.assets, this.progresses
|
|
2112
|
+
: new LazyAsset(data._id, data, this.collection, this.assets, this.progresses);
|
|
2039
2113
|
});
|
|
2040
2114
|
}
|
|
2041
2115
|
unlink(id) {
|
|
@@ -2050,8 +2124,10 @@ let LazyAssets = class LazyAssets {
|
|
|
2050
2124
|
LazyAssets = __decorate$q([
|
|
2051
2125
|
injectable(),
|
|
2052
2126
|
scoped(Lifecycle.ContainerScoped),
|
|
2053
|
-
__metadata$k("design:paramtypes", [MongoConnector,
|
|
2054
|
-
|
|
2127
|
+
__metadata$k("design:paramtypes", [MongoConnector,
|
|
2128
|
+
Assets,
|
|
2129
|
+
Progresses,
|
|
2130
|
+
JobManager])
|
|
2055
2131
|
], LazyAssets);
|
|
2056
2132
|
|
|
2057
2133
|
var __decorate$p = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -3752,14 +3828,15 @@ class LazyAssetGenerator {
|
|
|
3752
3828
|
get lazyAssets() {
|
|
3753
3829
|
return this.assetResolver.lazyAssets;
|
|
3754
3830
|
}
|
|
3755
|
-
process() {
|
|
3831
|
+
process(messaging) {
|
|
3756
3832
|
return __awaiter$1(this, void 0, void 0, function* () {
|
|
3757
3833
|
const lazyAsset = yield this.lazyAssets.read(this.lazyId);
|
|
3758
3834
|
let progress = yield this.progresses.get(lazyAsset.progressId);
|
|
3759
3835
|
if (!progress || progress.canceled)
|
|
3760
3836
|
return null;
|
|
3837
|
+
progress.setMessageBridge(messaging);
|
|
3761
3838
|
try {
|
|
3762
|
-
const asset = yield this.generate(progress);
|
|
3839
|
+
const asset = yield this.generate(progress, messaging);
|
|
3763
3840
|
progress = yield progress.load();
|
|
3764
3841
|
if (!progress || progress.canceled)
|
|
3765
3842
|
return null;
|
|
@@ -3826,7 +3903,8 @@ function createServices() {
|
|
|
3826
3903
|
new Parameter("nodeEnv", "development"),
|
|
3827
3904
|
new Parameter("appPort", 80),
|
|
3828
3905
|
new Parameter("zmqPort", 3000),
|
|
3829
|
-
new Parameter("
|
|
3906
|
+
new Parameter("zmqBackPort", 3100),
|
|
3907
|
+
new Parameter("zmqRemoteHost", "tcp://127.0.0.1"),
|
|
3830
3908
|
new Parameter("isWorker", false),
|
|
3831
3909
|
new Parameter("mainEndpoint", ""),
|
|
3832
3910
|
new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
@@ -4032,5 +4110,5 @@ function setupBackend(config, providers, parent) {
|
|
|
4032
4110
|
* Generated bundle index. Do not edit.
|
|
4033
4111
|
*/
|
|
4034
4112
|
|
|
4035
|
-
export { AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, convertValue, copy, copyStream, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, lookupPipelines, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, promiseTimeout, proxyFunction, proxyFunctions, rand, random, readAndDeleteFile, readFile, runCommand, setupBackend, streamToBuffer, ucFirst, valueToPromise, writeFile };
|
|
4113
|
+
export { AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, lookupPipelines, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, promiseTimeout, proxyFunction, proxyFunctions, rand, random, readAndDeleteFile, readFile, runCommand, setupBackend, streamToBuffer, ucFirst, valueToPromise, writeFile };
|
|
4036
4114
|
//# sourceMappingURL=stemy-backend.js.map
|