long-task-queue-reader 0.8.0-beta.1 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
- # [0.8.0-beta.1](https://github.com/Parsimotion/long-task-queue-reader/compare/v0.7.2...v0.8.0-beta.1) (2026-02-25)
1
+ # [0.8.0](https://github.com/Parsimotion/long-task-queue-reader/compare/v0.7.2...v0.8.0) (2026-03-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * delete overload method ([1628a7d](https://github.com/Parsimotion/long-task-queue-reader/commit/1628a7d1bae13a6140ef2bbcdf4255ab12f95390))
7
+ * finish after run once ([026faea](https://github.com/Parsimotion/long-task-queue-reader/commit/026faeaf8977dbfb529d495a721bd11c8bac1ba7))
2
8
 
3
9
 
4
10
  ### Features
5
11
 
6
- * add earlyFinish attribute ([063cc51](https://github.com/Parsimotion/long-task-queue-reader/commit/063cc51aa6a8564f8e90b883726f38f384834acd))
12
+ * 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@2.3.4", "", { "dependencies": { "punycode": "^1.4.1" } }, "sha512-TZ6TTfI5NtZnuyy/Kecv+CnoROnyXn2DN97LontgQpCwsX2XyLYCC0ENhYkehSOwAp8rTQKc/NUIF7BkQ5rKLA=="],
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,52 @@
1
+ (function() {
2
+ var BaseExecutionMode, _, convert;
3
+
4
+ _ = require("lodash");
5
+
6
+ convert = require("convert-units");
7
+
8
+ module.exports = BaseExecutionMode = (function() {
9
+ function BaseExecutionMode() {}
10
+
11
+ BaseExecutionMode.prototype._getMessage = function(reader) {
12
+ reader.emit("job-get-messages");
13
+ return reader.queue.messages({
14
+ maxMessages: 1,
15
+ visibilityTimeout: reader.visibilityTimeout
16
+ }).get(0);
17
+ };
18
+
19
+ BaseExecutionMode.prototype.executeOnce = function(reader) {
20
+ return this._getMessage(reader).tap((function(_this) {
21
+ return function(message) {
22
+ if (message != null) {
23
+ return reader._execute(message);
24
+ }
25
+ };
26
+ })(this)).tap((function(_this) {
27
+ return function() {
28
+ return reader.emit("job-finish-messages");
29
+ };
30
+ })(this))["catch"]((function(_this) {
31
+ return function(err) {
32
+ return reader.emit("job_error", {
33
+ method: "executionMode._executeOnce",
34
+ err: err
35
+ });
36
+ };
37
+ })(this));
38
+ };
39
+
40
+ BaseExecutionMode.prototype._nextTimeout = function(reader, message) {
41
+ if (_.isEmpty(message)) {
42
+ return convert(reader.waitingTime).from("s").to("ms");
43
+ } else {
44
+ return 0;
45
+ }
46
+ };
47
+
48
+ return BaseExecutionMode;
49
+
50
+ })();
51
+
52
+ }).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,33 @@
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
+ return OnceExecutionMode;
30
+
31
+ })(BaseExecutionMode);
32
+
33
+ }).call(this);
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- var EventEmitter, KeepAliveMessage, LongTaskQueueReader, MaxRetriesExceededException, Promise, _, convert, eventsToLog, winston,
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,23 @@
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
32
  "message-start": function(message) {
33
33
  return logger.info("Iniciando el proceso de un mensaje", message);
34
34
  },
@@ -51,85 +51,38 @@
51
51
  module.exports = LongTaskQueueReader = (function(superClass) {
52
52
  extend(LongTaskQueueReader, superClass);
53
53
 
54
- function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison) {
55
- var action, eventName, level, logger, ref, ref1, ref2, ref3, ref4, ref5, ref6, transports;
54
+ function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison, executionMode) {
55
+ var action, eventName, level, logger, ref, ref1, ref2, ref3, ref4, ref5, transports;
56
56
  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, this.earlyFinish = (ref3 = arg.earlyFinish) != null ? ref3 : false;
58
- level = (ref4 = arg1.level) != null ? ref4 : "info", transports = (ref5 = arg1.transports) != null ? ref5 : [];
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 = (ref3 = arg1.level) != null ? ref3 : "info", transports = (ref4 = arg1.transports) != null ? ref4 : [];
59
59
  this.MessageExecutor = MessageExecutor;
60
60
  this.runner = runner;
61
61
  this.fromPoison = fromPoison;
62
+ if (executionMode == null) {
63
+ executionMode = new ContinuousExecutionMode();
64
+ }
62
65
  this._touch = bind(this._touch, this);
63
66
  this._removeSafety = bind(this._removeSafety, this);
64
67
  this._createKeepAlive = bind(this._createKeepAlive, this);
65
68
  this._sendToPoison = bind(this._sendToPoison, this);
66
69
  this._execute = bind(this._execute, this);
67
70
  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
71
  this.start = bind(this.start, this);
72
+ this.executionMode = executionMode;
72
73
  logger = new winston.Logger({
73
74
  level: level,
74
75
  transports: transports
75
76
  });
76
- ref6 = eventsToLog(logger);
77
- for (eventName in ref6) {
78
- action = ref6[eventName];
77
+ ref5 = eventsToLog(logger);
78
+ for (eventName in ref5) {
79
+ action = ref5[eventName];
79
80
  this.on("" + eventName, action);
80
81
  }
81
82
  }
82
83
 
83
84
  LongTaskQueueReader.prototype.start = function() {
84
- return this._initNewTask();
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
- }
85
+ return this.executionMode.start(this);
133
86
  };
134
87
 
135
88
  LongTaskQueueReader.prototype._buildExecutor = function(message) {
@@ -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, this.earlyFinish = opts.earlyFinish;
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "long-task-queue-reader",
3
- "version": "0.8.0-beta.1",
3
+ "version": "0.8.0",
4
4
  "description": "long-task-queue-reader",
5
5
  "main": "index.js",
6
6
  "scripts": {