long-task-queue-reader 0.8.0-beta.1 → 0.8.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/CHANGELOG.md +15 -2
- package/bun.lock +15 -5
- package/lib/executionModes/baseExecutionMode.js +65 -0
- package/lib/executionModes/continuousExecutionMode.js +29 -0
- package/lib/executionModes/onceExecutionMode.js +42 -0
- package/lib/longTaskQueueReader.js +23 -73
- package/lib/longTaskQueueReaderBuilder.js +16 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
## [0.8.1](https://github.com/Parsimotion/long-task-queue-reader/compare/v0.8.0...v0.8.1) (2026-03-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* end process after getting an error ([8522d15](https://github.com/Parsimotion/long-task-queue-reader/commit/8522d15c3bf9ca5d3bb404638c1ed4f2951335db))
|
|
7
|
+
|
|
8
|
+
# [0.8.0](https://github.com/Parsimotion/long-task-queue-reader/compare/v0.7.2...v0.8.0) (2026-03-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* delete overload method ([1628a7d](https://github.com/Parsimotion/long-task-queue-reader/commit/1628a7d1bae13a6140ef2bbcdf4255ab12f95390))
|
|
14
|
+
* finish after run once ([026faea](https://github.com/Parsimotion/long-task-queue-reader/commit/026faeaf8977dbfb529d495a721bd11c8bac1ba7))
|
|
2
15
|
|
|
3
16
|
|
|
4
17
|
### Features
|
|
5
18
|
|
|
6
|
-
* add
|
|
19
|
+
* add once and continuous execution mode ([2893dea](https://github.com/Parsimotion/long-task-queue-reader/commit/2893dea67c6fbef28c257898774a6c173de0b2e9))
|
package/bun.lock
CHANGED
|
@@ -1128,13 +1128,17 @@
|
|
|
1128
1128
|
|
|
1129
1129
|
"thunkify": ["thunkify@2.1.2", "", {}, "sha512-w9foI80XcGImrhMQ19pxunaEC5Rp2uzxZZg4XBAFRfiLOplk3F0l7wo+bO16vC2/nlQfR/mXZxcduo0MF2GWLg=="],
|
|
1130
1130
|
|
|
1131
|
+
"tldts": ["tldts@7.0.23", "", { "dependencies": { "tldts-core": "^7.0.23" }, "bin": { "tldts": "bin/cli.js" } }, "sha512-ASdhgQIBSay0R/eXggAkQ53G4nTJqTXqC2kbaBbdDwM7SkjyZyO0OaaN1/FH7U/yCeqOHDwFO5j8+Os/IS1dXw=="],
|
|
1132
|
+
|
|
1133
|
+
"tldts-core": ["tldts-core@7.0.23", "", {}, "sha512-0g9vrtDQLrNIiCj22HSe9d4mLVG3g5ph5DZ8zCKBr4OtrspmNB6ss7hVyzArAeE88ceZocIEGkyW1Ime7fxPtQ=="],
|
|
1134
|
+
|
|
1131
1135
|
"to-buffer": ["to-buffer@1.2.2", "", { "dependencies": { "isarray": "^2.0.5", "safe-buffer": "^5.2.1", "typed-array-buffer": "^1.0.3" } }, "sha512-db0E3UJjcFhpDhAF4tLo03oli3pwl3dbnzXOUIlRKrp+ldk/VUxzpWYZENsw2SZiuBjHAk7DfB0VU7NKdpb6sw=="],
|
|
1132
1136
|
|
|
1133
1137
|
"to-regex-range": ["to-regex-range@5.0.1", "", { "dependencies": { "is-number": "^7.0.0" } }, "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ=="],
|
|
1134
1138
|
|
|
1135
1139
|
"toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="],
|
|
1136
1140
|
|
|
1137
|
-
"tough-cookie": ["tough-cookie@
|
|
1141
|
+
"tough-cookie": ["tough-cookie@6.0.0", "", { "dependencies": { "tldts": "^7.0.5" } }, "sha512-kXuRi1mtaKMrsLUxz3sQYvVl37B0Ns6MzfrtV5DvJceE9bPyspOqk9xxv7XbZWcfLWbFmm997vl83qUWVJA64w=="],
|
|
1138
1142
|
|
|
1139
1143
|
"trim-newlines": ["trim-newlines@3.0.1", "", {}, "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw=="],
|
|
1140
1144
|
|
|
@@ -1456,8 +1460,6 @@
|
|
|
1456
1460
|
|
|
1457
1461
|
"to-buffer/isarray": ["isarray@2.0.5", "", {}, "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw=="],
|
|
1458
1462
|
|
|
1459
|
-
"tough-cookie/punycode": ["punycode@1.4.1", "", {}, "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ=="],
|
|
1460
|
-
|
|
1461
1463
|
"uri-js/punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="],
|
|
1462
1464
|
|
|
1463
1465
|
"verror/assert-plus": ["assert-plus@1.0.0", "", {}, "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw=="],
|
|
@@ -1468,10 +1470,14 @@
|
|
|
1468
1470
|
|
|
1469
1471
|
"winston/async": ["async@2.6.4", "", { "dependencies": { "lodash": "^4.17.14" } }, "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA=="],
|
|
1470
1472
|
|
|
1473
|
+
"winston-azure-blob-transport/async": ["async@2.6.4", "", { "dependencies": { "lodash": "^4.17.14" } }, "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA=="],
|
|
1474
|
+
|
|
1471
1475
|
"winston-azure-blob-transport/azure-storage": ["azure-storage@2.10.7", "", { "dependencies": { "browserify-mime": "^1.2.9", "extend": "^3.0.2", "json-edm-parser": "~0.1.2", "json-schema": "~0.4.0", "md5.js": "^1.3.4", "readable-stream": "^2.0.0", "request": "^2.86.0", "underscore": "^1.12.1", "uuid": "^3.0.0", "validator": "^13.7.0", "xml2js": "~0.2.8", "xmlbuilder": "^9.0.7" } }, "sha512-4oeFGtn3Ziw/fGs/zkoIpKKtygnCVIcZwzJ7UQzKTxhkGQqVCByOFbYqMGYR3L+wOsunX9lNfD0jc51SQuKSSA=="],
|
|
1472
1476
|
|
|
1473
1477
|
"winston-azure-blob-transport/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
|
1474
1478
|
|
|
1479
|
+
"winston-cloudwatch/async": ["async@2.6.4", "", { "dependencies": { "lodash": "^4.17.14" } }, "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA=="],
|
|
1480
|
+
|
|
1475
1481
|
"winston-cloudwatch/chalk": ["chalk@1.1.3", "", { "dependencies": { "ansi-styles": "^2.2.1", "escape-string-regexp": "^1.0.2", "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" } }, "sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A=="],
|
|
1476
1482
|
|
|
1477
1483
|
"wrap-ansi/ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
|
|
@@ -1534,6 +1540,8 @@
|
|
|
1534
1540
|
|
|
1535
1541
|
"azure-storage/request/qs": ["qs@6.2.6", "", {}, "sha512-s7rExpMYwBiNpqSVXYeN7DIJL3wSVt3FgoWl2ypw3oyTALVuaNvJn/COGFwEEZgueRCLHmtoBXtD4lgtZYY5Vg=="],
|
|
1536
1542
|
|
|
1543
|
+
"azure-storage/request/tough-cookie": ["tough-cookie@2.3.4", "", { "dependencies": { "punycode": "^1.4.1" } }, "sha512-TZ6TTfI5NtZnuyy/Kecv+CnoROnyXn2DN97LontgQpCwsX2XyLYCC0ENhYkehSOwAp8rTQKc/NUIF7BkQ5rKLA=="],
|
|
1544
|
+
|
|
1537
1545
|
"azure-storage/xml2js/sax": ["sax@0.5.2", "", {}, "sha512-C1SZ6m6CbGBMGPPDfmx/lsgvtQqfLwPq4aRJmrlusZ27CYPaza0IK0/c+uCdvYvyKAsAg0eJFoQwSES7xj4XqA=="],
|
|
1538
1546
|
|
|
1539
1547
|
"chalk/strip-ansi/ansi-regex": ["ansi-regex@1.1.1", "", {}, "sha512-q5i8bFLg2wDfsuR56c1NzlJFPzVD+9mxhDrhqOGigEFa87OZHlF+9dWeGWzVTP/0ECiA/JUGzfzRr2t3eYORRw=="],
|
|
@@ -1578,6 +1586,8 @@
|
|
|
1578
1586
|
|
|
1579
1587
|
"execa/cross-spawn/shebang-command": ["shebang-command@1.2.0", "", { "dependencies": { "shebang-regex": "^1.0.0" } }, "sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg=="],
|
|
1580
1588
|
|
|
1589
|
+
"findup-sync/glob/minimatch": ["minimatch@3.1.5", "", { "dependencies": { "brace-expansion": "^1.1.7" } }, "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w=="],
|
|
1590
|
+
|
|
1581
1591
|
"flat-cache/rimraf/glob": ["glob@7.2.3", "", { "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q=="],
|
|
1582
1592
|
|
|
1583
1593
|
"form-data/combined-stream/delayed-stream": ["delayed-stream@0.0.5", "", {}, "sha512-v+7uBd1pqe5YtgPacIIbZ8HuHeLFVNe4mUEyFDXL6KiqzEykjbw+5mXZXpGFgNVasdL4jWKgaKIXrEHiynN1LA=="],
|
|
@@ -1620,8 +1630,6 @@
|
|
|
1620
1630
|
|
|
1621
1631
|
"husky/chalk/supports-color": ["supports-color@5.5.0", "", { "dependencies": { "has-flag": "^3.0.0" } }, "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow=="],
|
|
1622
1632
|
|
|
1623
|
-
"mocha/glob/minimatch": ["minimatch@3.1.5", "", { "dependencies": { "brace-expansion": "^1.1.7" } }, "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w=="],
|
|
1624
|
-
|
|
1625
1633
|
"mocha/mkdirp/minimist": ["minimist@0.0.8", "", {}, "sha512-miQKw5Hv4NS1Psg2517mV4e4dYNaO3++hjAvLOAzKqZ61rH8NS1SK+vbfBWZ5PY/Me/bEWhUwqMghEW5Fb9T7Q=="],
|
|
1626
1634
|
|
|
1627
1635
|
"pac-proxy-agent/debug/ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
|
@@ -1686,6 +1694,8 @@
|
|
|
1686
1694
|
|
|
1687
1695
|
"azure-storage/request/http-signature/assert-plus": ["assert-plus@0.2.0", "", {}, "sha512-u1L0ZLywRziOVjUhRxI0Qg9G+4RnFB9H/Rq40YWn0dieDgO7vAYeJz6jKAO6t/aruzlDFLAPkQTT87e+f8Imaw=="],
|
|
1688
1696
|
|
|
1697
|
+
"azure-storage/request/tough-cookie/punycode": ["punycode@1.4.1", "", {}, "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ=="],
|
|
1698
|
+
|
|
1689
1699
|
"conventional-commits-parser/meow/normalize-package-data/hosted-git-info": ["hosted-git-info@4.1.0", "", { "dependencies": { "lru-cache": "^6.0.0" } }, "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA=="],
|
|
1690
1700
|
|
|
1691
1701
|
"conventional-commits-parser/meow/normalize-package-data/semver": ["semver@7.7.4", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="],
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
var BaseExecutionMode, Promise, _, convert;
|
|
3
|
+
|
|
4
|
+
_ = require("lodash");
|
|
5
|
+
|
|
6
|
+
convert = require("convert-units");
|
|
7
|
+
|
|
8
|
+
Promise = require("bluebird");
|
|
9
|
+
|
|
10
|
+
module.exports = BaseExecutionMode = (function() {
|
|
11
|
+
function BaseExecutionMode() {}
|
|
12
|
+
|
|
13
|
+
BaseExecutionMode.prototype._getMessage = function(reader) {
|
|
14
|
+
reader.emit("job-get-messages");
|
|
15
|
+
return reader.queue.messages({
|
|
16
|
+
maxMessages: 1,
|
|
17
|
+
visibilityTimeout: reader.visibilityTimeout
|
|
18
|
+
}).get(0);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
BaseExecutionMode.prototype.executeOnce = function(reader) {
|
|
22
|
+
return this._getMessage(reader).tap((function(_this) {
|
|
23
|
+
return function(message) {
|
|
24
|
+
if (message != null) {
|
|
25
|
+
return reader._execute(message);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
})(this)).tap((function(_this) {
|
|
29
|
+
return function() {
|
|
30
|
+
return reader.emit("job-finish-messages");
|
|
31
|
+
};
|
|
32
|
+
})(this))["catch"]((function(_this) {
|
|
33
|
+
return function(err) {
|
|
34
|
+
return reader.emit("job_error", {
|
|
35
|
+
method: "executionMode._executeOnce",
|
|
36
|
+
err: err
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
})(this));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
BaseExecutionMode.prototype._nextTimeout = function(reader, message) {
|
|
43
|
+
if (_.isEmpty(message)) {
|
|
44
|
+
return convert(reader.waitingTime).from("s").to("ms");
|
|
45
|
+
} else {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
BaseExecutionMode.prototype.handleError = function(err, reader, keepAliveMessage, message) {
|
|
51
|
+
reader.emit("job_error", {
|
|
52
|
+
method: "executionMode.execute",
|
|
53
|
+
err: err,
|
|
54
|
+
message: message
|
|
55
|
+
});
|
|
56
|
+
return Promise.resolve().tap(function() {
|
|
57
|
+
return keepAliveMessage.destroy();
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return BaseExecutionMode;
|
|
62
|
+
|
|
63
|
+
})();
|
|
64
|
+
|
|
65
|
+
}).call(this);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
var BaseExecutionMode, ContinuousExecutionMode,
|
|
3
|
+
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
4
|
+
hasProp = {}.hasOwnProperty;
|
|
5
|
+
|
|
6
|
+
BaseExecutionMode = require("./baseExecutionMode");
|
|
7
|
+
|
|
8
|
+
module.exports = ContinuousExecutionMode = (function(superClass) {
|
|
9
|
+
extend(ContinuousExecutionMode, superClass);
|
|
10
|
+
|
|
11
|
+
function ContinuousExecutionMode() {
|
|
12
|
+
return ContinuousExecutionMode.__super__.constructor.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ContinuousExecutionMode.prototype.start = function(reader) {
|
|
16
|
+
return this.executeOnce(reader).then((function(_this) {
|
|
17
|
+
return function(message) {
|
|
18
|
+
setTimeout((function() {
|
|
19
|
+
return _this.start(reader);
|
|
20
|
+
}), _this._nextTimeout(reader, message));
|
|
21
|
+
};
|
|
22
|
+
})(this));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return ContinuousExecutionMode;
|
|
26
|
+
|
|
27
|
+
})(BaseExecutionMode);
|
|
28
|
+
|
|
29
|
+
}).call(this);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
var BaseExecutionMode, OnceExecutionMode,
|
|
3
|
+
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
4
|
+
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
5
|
+
hasProp = {}.hasOwnProperty;
|
|
6
|
+
|
|
7
|
+
BaseExecutionMode = require("./baseExecutionMode");
|
|
8
|
+
|
|
9
|
+
module.exports = OnceExecutionMode = (function(superClass) {
|
|
10
|
+
extend(OnceExecutionMode, superClass);
|
|
11
|
+
|
|
12
|
+
function OnceExecutionMode() {
|
|
13
|
+
this.start = bind(this.start, this);
|
|
14
|
+
return OnceExecutionMode.__super__.constructor.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
OnceExecutionMode.prototype.start = function(reader) {
|
|
18
|
+
return this.executeOnce(reader).tap((function(_this) {
|
|
19
|
+
return function() {
|
|
20
|
+
return reader.emit("job-finish");
|
|
21
|
+
};
|
|
22
|
+
})(this)).tap((function(_this) {
|
|
23
|
+
return function() {
|
|
24
|
+
return process.exit(0);
|
|
25
|
+
};
|
|
26
|
+
})(this));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
OnceExecutionMode.prototype.handleError = function(err, reader, keepAliveMessage, message) {
|
|
30
|
+
return OnceExecutionMode.__super__.handleError.call(this, err, reader, keepAliveMessage, message).then((function(_this) {
|
|
31
|
+
return function() {
|
|
32
|
+
reader.emit("job-error-finish");
|
|
33
|
+
return process.exit(1);
|
|
34
|
+
};
|
|
35
|
+
})(this));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return OnceExecutionMode;
|
|
39
|
+
|
|
40
|
+
})(BaseExecutionMode);
|
|
41
|
+
|
|
42
|
+
}).call(this);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function() {
|
|
2
|
-
var EventEmitter, KeepAliveMessage, LongTaskQueueReader, MaxRetriesExceededException, Promise, _,
|
|
2
|
+
var ContinuousExecutionMode, EventEmitter, KeepAliveMessage, LongTaskQueueReader, MaxRetriesExceededException, Promise, _, eventsToLog, winston,
|
|
3
3
|
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
4
4
|
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
5
5
|
hasProp = {}.hasOwnProperty;
|
|
@@ -12,23 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
EventEmitter = require("events").EventEmitter;
|
|
14
14
|
|
|
15
|
-
convert = require("convert-units");
|
|
16
|
-
|
|
17
15
|
KeepAliveMessage = require("./keepAliveMessage");
|
|
18
16
|
|
|
19
17
|
MaxRetriesExceededException = require("./maxRetriesExceededException");
|
|
20
18
|
|
|
19
|
+
ContinuousExecutionMode = require("./executionModes/continuousExecutionMode");
|
|
20
|
+
|
|
21
21
|
eventsToLog = function(logger) {
|
|
22
22
|
return {
|
|
23
23
|
"job-get-messages": function() {
|
|
24
24
|
return logger.info("Obteniendo mensajes nuevas");
|
|
25
25
|
},
|
|
26
|
-
"job-early-finish-messages": function() {
|
|
27
|
-
return logger.info("Finalizo la ejecucion de mensajes antes de tiempo");
|
|
28
|
-
},
|
|
29
26
|
"job-finish-messages": function() {
|
|
30
27
|
return logger.info("Finalizo la ejecucion de mensajes");
|
|
31
28
|
},
|
|
29
|
+
"job-finish": function() {
|
|
30
|
+
return logger.info("Finalizo la ejecucion");
|
|
31
|
+
},
|
|
32
|
+
"job-error-finish": function() {
|
|
33
|
+
return logger.info("Finalizo la ejecucion por un error");
|
|
34
|
+
},
|
|
32
35
|
"message-start": function(message) {
|
|
33
36
|
return logger.info("Iniciando el proceso de un mensaje", message);
|
|
34
37
|
},
|
|
@@ -51,85 +54,38 @@
|
|
|
51
54
|
module.exports = LongTaskQueueReader = (function(superClass) {
|
|
52
55
|
extend(LongTaskQueueReader, superClass);
|
|
53
56
|
|
|
54
|
-
function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison) {
|
|
55
|
-
var action, eventName, level, logger, ref, ref1, ref2, ref3, ref4, ref5,
|
|
57
|
+
function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison, executionMode) {
|
|
58
|
+
var action, eventName, level, logger, ref, ref1, ref2, ref3, ref4, ref5, transports;
|
|
56
59
|
this.queue = queue;
|
|
57
|
-
this.waitingTime = (ref = arg.waitingTime) != null ? ref : 60, this.visibilityTimeout = (ref1 = arg.visibilityTimeout) != null ? ref1 : 60, this.maxRetries = (ref2 = arg.maxRetries) != null ? ref2 : 10
|
|
58
|
-
level = (
|
|
60
|
+
this.waitingTime = (ref = arg.waitingTime) != null ? ref : 60, this.visibilityTimeout = (ref1 = arg.visibilityTimeout) != null ? ref1 : 60, this.maxRetries = (ref2 = arg.maxRetries) != null ? ref2 : 10;
|
|
61
|
+
level = (ref3 = arg1.level) != null ? ref3 : "info", transports = (ref4 = arg1.transports) != null ? ref4 : [];
|
|
59
62
|
this.MessageExecutor = MessageExecutor;
|
|
60
63
|
this.runner = runner;
|
|
61
64
|
this.fromPoison = fromPoison;
|
|
65
|
+
if (executionMode == null) {
|
|
66
|
+
executionMode = new ContinuousExecutionMode();
|
|
67
|
+
}
|
|
62
68
|
this._touch = bind(this._touch, this);
|
|
63
69
|
this._removeSafety = bind(this._removeSafety, this);
|
|
64
70
|
this._createKeepAlive = bind(this._createKeepAlive, this);
|
|
65
71
|
this._sendToPoison = bind(this._sendToPoison, this);
|
|
66
72
|
this._execute = bind(this._execute, this);
|
|
67
73
|
this._buildExecutor = bind(this._buildExecutor, this);
|
|
68
|
-
this._nextTimeout = bind(this._nextTimeout, this);
|
|
69
|
-
this._executePendingSynchronization = bind(this._executePendingSynchronization, this);
|
|
70
|
-
this._initNewTask = bind(this._initNewTask, this);
|
|
71
74
|
this.start = bind(this.start, this);
|
|
75
|
+
this.executionMode = executionMode;
|
|
72
76
|
logger = new winston.Logger({
|
|
73
77
|
level: level,
|
|
74
78
|
transports: transports
|
|
75
79
|
});
|
|
76
|
-
|
|
77
|
-
for (eventName in
|
|
78
|
-
action =
|
|
80
|
+
ref5 = eventsToLog(logger);
|
|
81
|
+
for (eventName in ref5) {
|
|
82
|
+
action = ref5[eventName];
|
|
79
83
|
this.on("" + eventName, action);
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
LongTaskQueueReader.prototype.start = function() {
|
|
84
|
-
return this.
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
LongTaskQueueReader.prototype._initNewTask = function() {
|
|
88
|
-
return this._executePendingSynchronization().then((function(_this) {
|
|
89
|
-
return function(message) {
|
|
90
|
-
setTimeout(_this._initNewTask, _this._nextTimeout(message));
|
|
91
|
-
};
|
|
92
|
-
})(this));
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
LongTaskQueueReader.prototype._executePendingSynchronization = function() {
|
|
96
|
-
this.emit("job-get-messages");
|
|
97
|
-
return this.queue.messages({
|
|
98
|
-
maxMessages: 1,
|
|
99
|
-
visibilityTimeout: this.visibilityTimeout
|
|
100
|
-
}).get(0).tap((function(_this) {
|
|
101
|
-
return function(message) {
|
|
102
|
-
if (message != null) {
|
|
103
|
-
return _this._execute(message);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
})(this)).tap((function(_this) {
|
|
107
|
-
return function() {
|
|
108
|
-
return _this.emit("job-finish-messages");
|
|
109
|
-
};
|
|
110
|
-
})(this)).tap((function(_this) {
|
|
111
|
-
return function() {
|
|
112
|
-
if (_this.earlyFinish) {
|
|
113
|
-
_this.emit("job-early-finish-messages");
|
|
114
|
-
return process.exit(0);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
})(this))["catch"]((function(_this) {
|
|
118
|
-
return function(err) {
|
|
119
|
-
return _this.emit("job_error", {
|
|
120
|
-
method: "_executePendingSynchronization",
|
|
121
|
-
err: err
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
})(this));
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
LongTaskQueueReader.prototype._nextTimeout = function(message) {
|
|
128
|
-
if (_.isEmpty(message)) {
|
|
129
|
-
return convert(this.waitingTime).from("s").to("ms");
|
|
130
|
-
} else {
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
88
|
+
return this.executionMode.start(this);
|
|
133
89
|
};
|
|
134
90
|
|
|
135
91
|
LongTaskQueueReader.prototype._buildExecutor = function(message) {
|
|
@@ -156,15 +112,9 @@
|
|
|
156
112
|
};
|
|
157
113
|
})(this))["catch"]((function(_this) {
|
|
158
114
|
return function(err) {
|
|
159
|
-
return _this.
|
|
160
|
-
method: "_execute",
|
|
161
|
-
err: err,
|
|
162
|
-
message: message
|
|
163
|
-
});
|
|
115
|
+
return _this.executionMode.handleError(err, _this, keepAliveMessage, message);
|
|
164
116
|
};
|
|
165
|
-
})(this)).
|
|
166
|
-
return keepAliveMessage.destroy();
|
|
167
|
-
}).then((function(_this) {
|
|
117
|
+
})(this)).then((function(_this) {
|
|
168
118
|
return function() {
|
|
169
119
|
return _this.emit("message-finish", message);
|
|
170
120
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function() {
|
|
2
|
-
var LongTaskQueueReaderBuilder, Promise, QueueProcessor, winston;
|
|
2
|
+
var LongTaskQueueReaderBuilder, Promise, QueueProcessor, executionModes, winston;
|
|
3
3
|
|
|
4
4
|
winston = require("winston");
|
|
5
5
|
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
QueueProcessor = require("./longTaskQueueReader");
|
|
9
9
|
|
|
10
|
+
executionModes = {
|
|
11
|
+
continuous: require("./executionModes/continuousExecutionMode"),
|
|
12
|
+
once: require("./executionModes/onceExecutionMode")
|
|
13
|
+
};
|
|
14
|
+
|
|
10
15
|
module.exports = LongTaskQueueReaderBuilder = (function() {
|
|
11
16
|
function LongTaskQueueReaderBuilder(implementation, poison) {
|
|
12
17
|
this.implementation = implementation != null ? implementation : "azure";
|
|
@@ -30,7 +35,7 @@
|
|
|
30
35
|
|
|
31
36
|
LongTaskQueueReaderBuilder.prototype.withQueue = function(opts) {
|
|
32
37
|
var Queue;
|
|
33
|
-
this.waitingTime = opts.waitingTime, this.timeToUpdateMessage = opts.timeToUpdateMessage
|
|
38
|
+
this.waitingTime = opts.waitingTime, this.timeToUpdateMessage = opts.timeToUpdateMessage;
|
|
34
39
|
Queue = this._internalRequire("queue" + (this.poison ? ".poison" : ""));
|
|
35
40
|
this.queue = new Queue(opts);
|
|
36
41
|
this.dependencies.push(this.queue);
|
|
@@ -52,6 +57,13 @@
|
|
|
52
57
|
return this;
|
|
53
58
|
};
|
|
54
59
|
|
|
60
|
+
LongTaskQueueReaderBuilder.prototype.withExecutionMode = function(mode) {
|
|
61
|
+
var ExecutionMode;
|
|
62
|
+
ExecutionMode = executionModes[mode] || executionModes.continuous;
|
|
63
|
+
this.executionMode = new ExecutionMode();
|
|
64
|
+
return this;
|
|
65
|
+
};
|
|
66
|
+
|
|
55
67
|
LongTaskQueueReaderBuilder.prototype.withImplementation = function(implementation) {
|
|
56
68
|
this.implementation = implementation;
|
|
57
69
|
return this;
|
|
@@ -65,11 +77,10 @@
|
|
|
65
77
|
return new QueueProcessor(_this.queue, {
|
|
66
78
|
waitingTime: _this.waitingTime,
|
|
67
79
|
timeToUpdateMessage: _this.timeToUpdateMessage,
|
|
68
|
-
maxRetries: _this.maxRetries
|
|
69
|
-
earlyFinish: _this.earlyFinish
|
|
80
|
+
maxRetries: _this.maxRetries
|
|
70
81
|
}, {
|
|
71
82
|
transports: _this.transports
|
|
72
|
-
}, _this._internalRequire("messageExecutor"), _this.runner, _this.poison);
|
|
83
|
+
}, _this._internalRequire("messageExecutor"), _this.runner, _this.poison, _this.executionMode);
|
|
73
84
|
};
|
|
74
85
|
})(this));
|
|
75
86
|
};
|