long-task-queue-reader 0.7.3-test.1 → 0.8.0-alpha.2

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/bunfig.toml ADDED
@@ -0,0 +1,5 @@
1
+ [install]
2
+ registry = "https://registry.npmjs.org"
3
+
4
+ [install.scopes]
5
+ "@producteca" = { token = "$NPM_TOKEN", url = "https://registry.npmjs.org/" }
@@ -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,25 @@
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);
19
+ };
20
+
21
+ return OnceExecutionMode;
22
+
23
+ })(BaseExecutionMode);
24
+
25
+ }).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,12 +12,12 @@
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() {
@@ -48,7 +48,7 @@
48
48
  module.exports = LongTaskQueueReader = (function(superClass) {
49
49
  extend(LongTaskQueueReader, superClass);
50
50
 
51
- function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison) {
51
+ function LongTaskQueueReader(queue, arg, arg1, MessageExecutor, runner, fromPoison, executionMode) {
52
52
  var action, eventName, level, logger, ref, ref1, ref2, ref3, ref4, ref5, transports;
53
53
  this.queue = queue;
54
54
  this.waitingTime = (ref = arg.waitingTime) != null ? ref : 60, this.visibilityTimeout = (ref1 = arg.visibilityTimeout) != null ? ref1 : 60, this.maxRetries = (ref2 = arg.maxRetries) != null ? ref2 : 10;
@@ -56,16 +56,17 @@
56
56
  this.MessageExecutor = MessageExecutor;
57
57
  this.runner = runner;
58
58
  this.fromPoison = fromPoison;
59
+ if (executionMode == null) {
60
+ executionMode = new ContinuousExecutionMode();
61
+ }
59
62
  this._touch = bind(this._touch, this);
60
63
  this._removeSafety = bind(this._removeSafety, this);
61
64
  this._createKeepAlive = bind(this._createKeepAlive, this);
62
65
  this._sendToPoison = bind(this._sendToPoison, this);
63
66
  this._execute = bind(this._execute, this);
64
67
  this._buildExecutor = bind(this._buildExecutor, this);
65
- this._nextTimeout = bind(this._nextTimeout, this);
66
- this._executePendingSynchronization = bind(this._executePendingSynchronization, this);
67
- this._initNewTask = bind(this._initNewTask, this);
68
68
  this.start = bind(this.start, this);
69
+ this.executionMode = executionMode;
69
70
  logger = new winston.Logger({
70
71
  level: level,
71
72
  transports: transports
@@ -78,48 +79,7 @@
78
79
  }
79
80
 
80
81
  LongTaskQueueReader.prototype.start = function() {
81
- return this._initNewTask();
82
- };
83
-
84
- LongTaskQueueReader.prototype._initNewTask = function() {
85
- return this._executePendingSynchronization().then((function(_this) {
86
- return function(message) {
87
- setTimeout(_this._initNewTask, _this._nextTimeout(message));
88
- };
89
- })(this));
90
- };
91
-
92
- LongTaskQueueReader.prototype._executePendingSynchronization = function() {
93
- this.emit("job-get-messages");
94
- return this.queue.messages({
95
- maxMessages: 1,
96
- visibilityTimeout: this.visibilityTimeout
97
- }).get(0).tap((function(_this) {
98
- return function(message) {
99
- if (message != null) {
100
- return _this._execute(message);
101
- }
102
- };
103
- })(this)).tap((function(_this) {
104
- return function() {
105
- return _this.emit("job-finish-messages");
106
- };
107
- })(this))["catch"]((function(_this) {
108
- return function(err) {
109
- return _this.emit("job_error", {
110
- method: "_executePendingSynchronization",
111
- err: err
112
- });
113
- };
114
- })(this));
115
- };
116
-
117
- LongTaskQueueReader.prototype._nextTimeout = function(message) {
118
- if (_.isEmpty(message)) {
119
- return convert(this.waitingTime).from("s").to("ms");
120
- } else {
121
- return 0;
122
- }
82
+ return this.executionMode.start(this);
123
83
  };
124
84
 
125
85
  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";
@@ -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;
@@ -68,7 +80,7 @@
68
80
  maxRetries: _this.maxRetries
69
81
  }, {
70
82
  transports: _this.transports
71
- }, _this._internalRequire("messageExecutor"), _this.runner, _this.poison);
83
+ }, _this._internalRequire("messageExecutor"), _this.runner, _this.poison, _this.executionMode);
72
84
  };
73
85
  })(this));
74
86
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "long-task-queue-reader",
3
- "version": "0.7.3-test.1",
3
+ "version": "0.8.0-alpha.2",
4
4
  "description": "long-task-queue-reader",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@
12
12
  "url": "git+https://github.com/Parsimotion/long-task-queue-reader.git"
13
13
  },
14
14
  "dependencies": {
15
- "@producteca/releaseteca": "^1.2.0",
16
15
  "async": "~2.1.2",
17
16
  "aws-sdk": "^2.687.0",
18
17
  "azure-queue-node": "~1.1.0",
@@ -26,8 +25,7 @@
26
25
  "winston-cloudwatch": "^1.13.1"
27
26
  },
28
27
  "devDependencies": {
29
- "@commitlint/cli": "^8.3.5",
30
- "@commitlint/config-conventional": "^8.3.4",
28
+ "@producteca/linterteca": "^1.3.2",
31
29
  "coffee-script": "~1.11.0",
32
30
  "grunt": "~1.0.1",
33
31
  "grunt-bump": "~0.8.0",
@@ -43,7 +41,9 @@
43
41
  },
44
42
  "husky": {
45
43
  "hooks": {
46
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
44
+ "commit-msg": "npx linterteca-commitlint --edit $1",
45
+ "pre-commit": "npx lint-staged",
46
+ "pre-push": "npx linterteca"
47
47
  }
48
48
  },
49
49
  "author": "Parsimotion",
@@ -51,5 +51,15 @@
51
51
  "bugs": {
52
52
  "url": "https://github.com/Parsimotion/long-task-queue-reader/issues"
53
53
  },
54
- "homepage": "https://github.com/Parsimotion/long-task-queue-reader#readme"
54
+ "homepage": "https://github.com/Parsimotion/long-task-queue-reader#readme",
55
+ "lint-staged": {
56
+ "*.{js,jsx}": [
57
+ "linterteca-lint"
58
+ ]
59
+ },
60
+ "trustedDependencies": [
61
+ "aws-sdk",
62
+ "core-js",
63
+ "husky"
64
+ ]
55
65
  }