notification-processor 4.7.0 → 4.10.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/.github/PULL_REQUEST_TEMPLATE.md +2 -0
- package/copyToFunction +9 -0
- package/lib/exceptions/non.retryable.js +1 -1
- package/lib/index.js +1 -1
- package/lib/observers/deadLetterSucceeded.observer.js +1 -1
- package/lib/observers/delay.levels.js +1 -1
- package/lib/observers/delay.observer.js +1 -1
- package/lib/observers/didLastRetry.observer.js +1 -1
- package/lib/observers/incidentsApi.observer.js +5 -6
- package/lib/observers/logger.observer.js +1 -1
- package/lib/observers/redis.observer.js +1 -1
- package/lib/processor.builder.js +1 -1
- package/lib/processor.js +1 -1
- package/lib/processors/deadletter.processor.js +1 -1
- package/lib/processors/job/index.js +1 -1
- package/lib/processors/job/job.processor.js +37 -5
- package/lib/processors/job/notification.api.js +143 -20
- package/lib/processors/maxRetries.processor.js +1 -1
- package/lib/processors/request.async.processor.js +5 -3
- package/lib/processors/request.processor.js +1 -1
- package/lib/processors/requestWithRetries.async.processor.js +1 -1
- package/lib/senders/async.producteca.sender.js +52 -0
- package/lib/senders/index.js +3 -2
- package/lib/senders/meli.sender.js +1 -1
- package/lib/senders/producteca.sender.js +1 -1
- package/lib/services/oAuthApi.js +54 -0
- package/lib/services/redis.js +1 -1
- package/lib/sources/index.js +1 -1
- package/lib/sources/queue.source.js +1 -1
- package/lib/sources/service.bus.source.js +1 -1
- package/lib/sources/table.source.js +1 -1
- package/lib/sources/unknown.source.js +1 -1
- package/lib/specHelpers/fixture.js +1 -1
- package/lib/specHelpers/redis.observer.mock.js +1 -1
- package/notification-processor.sublime-workspace +1506 -0
- package/package.json +3 -1
package/copyToFunction
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
FUNCTION=$1
|
|
3
|
+
|
|
4
|
+
npm run build
|
|
5
|
+
echo "Removing old version from $FUNCTION"
|
|
6
|
+
rm -rf "../$FUNCTION/node_modules/notification-processor/lib/"
|
|
7
|
+
echo "Removed. Copying new version to $FUNCTION"
|
|
8
|
+
cp -R lib/ "../$FUNCTION/node_modules/notification-processor/lib/"
|
|
9
|
+
echo "Done"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
4
|
|
|
5
|
-
// Generated by CoffeeScript 2.
|
|
5
|
+
// Generated by CoffeeScript 2.7.0
|
|
6
6
|
(function () {
|
|
7
7
|
var NonRetryable;
|
|
8
8
|
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
-
// Generated by CoffeeScript 2.
|
|
11
|
+
// Generated by CoffeeScript 2.7.0
|
|
12
12
|
(function () {
|
|
13
13
|
var DeadLetterSucceededObserver,
|
|
14
14
|
Promise,
|
|
@@ -8,7 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
-
// Generated by CoffeeScript 2.
|
|
11
|
+
// Generated by CoffeeScript 2.7.0
|
|
12
12
|
(function () {
|
|
13
13
|
var DelayObserver,
|
|
14
14
|
Promise,
|
|
@@ -8,7 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
-
// Generated by CoffeeScript 2.
|
|
11
|
+
// Generated by CoffeeScript 2.7.0
|
|
12
12
|
(function () {
|
|
13
13
|
var DidLastRetry,
|
|
14
14
|
Promise,
|
|
@@ -4,7 +4,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
// Generated by CoffeeScript 2.
|
|
7
|
+
// Generated by CoffeeScript 2.7.0
|
|
8
8
|
(function () {
|
|
9
9
|
var IncidentsApiObserver, Promise, ServiceBusClient, _, debug, encode;
|
|
10
10
|
|
|
@@ -67,7 +67,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
67
67
|
return $message.tap(function (message) {
|
|
68
68
|
return debug("To publish message %o", message);
|
|
69
69
|
}).then(function (message) {
|
|
70
|
-
return _this.messageSender.send(
|
|
70
|
+
return _this.messageSender.send(message);
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
}, {
|
|
@@ -75,10 +75,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
75
75
|
value: function _mapper(id, notification, err) {
|
|
76
76
|
var _this2 = this;
|
|
77
77
|
|
|
78
|
-
Promise.promisifyAll(this.sender);
|
|
79
78
|
return Promise.props({
|
|
80
|
-
resource: this.sender.
|
|
81
|
-
user: this.sender.
|
|
79
|
+
resource: Promise.method(this.sender.resource)(notification),
|
|
80
|
+
user: Promise.method(this.sender.user)(notification)
|
|
82
81
|
}).then(function (_ref3) {
|
|
83
82
|
var resource = _ref3.resource,
|
|
84
83
|
user = _ref3.user;
|
|
@@ -96,7 +95,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
96
95
|
type: _.get(err, "type", "unknown_error"),
|
|
97
96
|
tags: _.get(err, "tags", [])
|
|
98
97
|
};
|
|
99
|
-
});
|
|
98
|
+
}).then(JSON.stringify);
|
|
100
99
|
}
|
|
101
100
|
}, {
|
|
102
101
|
key: "_buildMessageSender",
|
|
@@ -4,7 +4,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
// Generated by CoffeeScript 2.
|
|
7
|
+
// Generated by CoffeeScript 2.7.0
|
|
8
8
|
(function () {
|
|
9
9
|
var Promise, Redis, RedisObserver, _;
|
|
10
10
|
|
package/lib/processor.builder.js
CHANGED
|
@@ -4,7 +4,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
// Generated by CoffeeScript 2.
|
|
7
|
+
// Generated by CoffeeScript 2.7.0
|
|
8
8
|
(function () {
|
|
9
9
|
var MeliSender, Processor, ProcessorBuilder, ProductecaSender, QueueSource, ServiceBusSource, UnknownSource, _, logger;
|
|
10
10
|
|
package/lib/processor.js
CHANGED
|
@@ -8,7 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
-
// Generated by CoffeeScript 2.
|
|
11
|
+
// Generated by CoffeeScript 2.7.0
|
|
12
12
|
(function () {
|
|
13
13
|
var ENABLE_EVENTS,
|
|
14
14
|
EventEmitter,
|
|
@@ -8,7 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
-
// Generated by CoffeeScript 2.
|
|
11
|
+
// Generated by CoffeeScript 2.7.0
|
|
12
12
|
(function () {
|
|
13
13
|
var DeadletterProcessor, MaxRetriesProcessor, NonRetryable;
|
|
14
14
|
|
|
@@ -10,13 +10,14 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
10
10
|
|
|
11
11
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
12
12
|
|
|
13
|
-
// Generated by CoffeeScript 2.
|
|
13
|
+
// Generated by CoffeeScript 2.7.0
|
|
14
14
|
(function () {
|
|
15
15
|
var JobProcessor,
|
|
16
16
|
MaxRetriesProcessor,
|
|
17
17
|
NonRetryable,
|
|
18
18
|
NotificationsApi,
|
|
19
19
|
_,
|
|
20
|
+
debug,
|
|
20
21
|
request,
|
|
21
22
|
boundMethodCheck = function boundMethodCheck(instance, Constructor) {
|
|
22
23
|
if (!(instance instanceof Constructor)) {
|
|
@@ -35,6 +36,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
35
36
|
|
|
36
37
|
NotificationsApi = require("./notification.api");
|
|
37
38
|
|
|
39
|
+
debug = require("debug")("notification-processor:job-processor");
|
|
40
|
+
|
|
38
41
|
module.exports = JobProcessor = function (_MaxRetriesProcessor) {
|
|
39
42
|
_inherits(JobProcessor, _MaxRetriesProcessor);
|
|
40
43
|
|
|
@@ -43,12 +46,15 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
43
46
|
|
|
44
47
|
var _this = _possibleConstructorReturn(this, (JobProcessor.__proto__ || Object.getPrototypeOf(JobProcessor)).call(this, args));
|
|
45
48
|
|
|
49
|
+
_this.process = _this.process.bind(_this);
|
|
46
50
|
_this._onSuccess_ = _this._onSuccess_.bind(_this);
|
|
47
51
|
_this._shouldRetry_ = _this._shouldRetry_.bind(_this);
|
|
48
52
|
_this._sanitizeError_ = _this._sanitizeError_.bind(_this);
|
|
49
53
|
_this._onMaxRetryExceeded_ = _this._onMaxRetryExceeded_.bind(_this);
|
|
50
54
|
_this._notificationsApi = _this._notificationsApi.bind(_this);
|
|
55
|
+
_this._ifJobIsNotStopped = _this._ifJobIsNotStopped.bind(_this);
|
|
51
56
|
_this.notificationApiUrl = args.notificationApiUrl;
|
|
57
|
+
_this.notificationApiAsyncUrl = args.notificationApiAsyncUrl;
|
|
52
58
|
_this.nonRetryable = args.nonRetryable;
|
|
53
59
|
return _this;
|
|
54
60
|
}
|
|
@@ -56,16 +62,25 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
56
62
|
_createClass(JobProcessor, [{
|
|
57
63
|
key: "process",
|
|
58
64
|
value: function process(notification) {
|
|
59
|
-
|
|
65
|
+
var _this2 = this;
|
|
66
|
+
|
|
67
|
+
boundMethodCheck(this, JobProcessor);
|
|
68
|
+
return this._ifJobIsNotStopped(notification.message, function () {
|
|
69
|
+
return _get(JobProcessor.prototype.__proto__ || Object.getPrototypeOf(JobProcessor.prototype), "process", _this2).call(_this2, notification).thenReturn();
|
|
70
|
+
});
|
|
60
71
|
}
|
|
61
72
|
}, {
|
|
62
73
|
key: "_onSuccess_",
|
|
63
74
|
value: function _onSuccess_(_ref, _ref2) {
|
|
75
|
+
var _this3 = this;
|
|
76
|
+
|
|
64
77
|
var message = _ref.message;
|
|
65
78
|
var statusCode = _ref2.statusCode;
|
|
66
79
|
|
|
67
80
|
boundMethodCheck(this, JobProcessor);
|
|
68
|
-
return this.
|
|
81
|
+
return this._ifJobIsNotStopped(message, function () {
|
|
82
|
+
return _this3._notificationsApi(message).success({ message: message, statusCode: statusCode });
|
|
83
|
+
});
|
|
69
84
|
}
|
|
70
85
|
}, {
|
|
71
86
|
key: "_shouldRetry_",
|
|
@@ -83,6 +98,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
83
98
|
}, {
|
|
84
99
|
key: "_onMaxRetryExceeded_",
|
|
85
100
|
value: function _onMaxRetryExceeded_(_ref3, error) {
|
|
101
|
+
var _this4 = this;
|
|
102
|
+
|
|
86
103
|
var message = _ref3.message;
|
|
87
104
|
|
|
88
105
|
var errorMessage;
|
|
@@ -93,7 +110,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
93
110
|
error: error,
|
|
94
111
|
request: _.omit(error.detail.request, ["resolveWithFullResponse"])
|
|
95
112
|
};
|
|
96
|
-
return this.
|
|
113
|
+
return this._ifJobIsNotStopped(message, function () {
|
|
114
|
+
return _this4._notificationsApi(message).fail(errorMessage).throw(new NonRetryable("Max retry exceeded", error));
|
|
115
|
+
});
|
|
97
116
|
}
|
|
98
117
|
}, {
|
|
99
118
|
key: "_notificationsApi",
|
|
@@ -107,7 +126,20 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
107
126
|
Key: "Authorization"
|
|
108
127
|
}).Value,
|
|
109
128
|
jobId: JobId,
|
|
110
|
-
notificationApiUrl: this.notificationApiUrl
|
|
129
|
+
notificationApiUrl: this.notificationApiUrl,
|
|
130
|
+
notificationApiAsyncUrl: this.notificationApiAsyncUrl
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
key: "_ifJobIsNotStopped",
|
|
135
|
+
value: function _ifJobIsNotStopped(message, action) {
|
|
136
|
+
boundMethodCheck(this, JobProcessor);
|
|
137
|
+
return this._notificationsApi(message).jobIsStopped().then(function (jobIsStopped) {
|
|
138
|
+
if (jobIsStopped) {
|
|
139
|
+
console.log("job " + message.JobId + " is stopped, ignoring action");
|
|
140
|
+
return Promise.resolve();
|
|
141
|
+
}
|
|
142
|
+
return action();
|
|
111
143
|
});
|
|
112
144
|
}
|
|
113
145
|
}]);
|
|
@@ -4,75 +4,193 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
// Generated by CoffeeScript 2.
|
|
7
|
+
// Generated by CoffeeScript 2.7.0
|
|
8
8
|
(function () {
|
|
9
|
-
var NotificationsApi, _,
|
|
9
|
+
var DEFAULT_NOTIFICATIONS_API_ASYNC_URL, HOUR, NOTIFICATIONS_API_JOBS_CACHE_TTL, NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL, NodeCache, NotificationsApi, Promise, _, jobsCache, requestPromise, retry, stoppedJobsCache;
|
|
10
10
|
|
|
11
11
|
_ = require("lodash");
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
requestPromise = require("request-promise");
|
|
14
14
|
|
|
15
15
|
retry = require("bluebird-retry");
|
|
16
16
|
|
|
17
|
+
Promise = require("bluebird");
|
|
18
|
+
|
|
19
|
+
NodeCache = require("node-cache");
|
|
20
|
+
|
|
21
|
+
NOTIFICATIONS_API_JOBS_CACHE_TTL = parseInt(process.env.NOTIFICATIONS_API_JOBS_CACHE_TTL) || 5;
|
|
22
|
+
|
|
23
|
+
NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL = parseInt(process.env.NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL) || 2;
|
|
24
|
+
|
|
25
|
+
DEFAULT_NOTIFICATIONS_API_ASYNC_URL = process.env.DEFAULT_NOTIFICATIONS_API_ASYNC_URL || "https://apps.producteca.com/aws/notifications-api-async";
|
|
26
|
+
|
|
27
|
+
HOUR = 60 * 60;
|
|
28
|
+
|
|
29
|
+
//Para minimizar las requests a notifications-api, cachea unos segundos el estado del job
|
|
30
|
+
jobsCache = new NodeCache({
|
|
31
|
+
stdTTL: NOTIFICATIONS_API_JOBS_CACHE_TTL
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//A nivel dominio, podria ser cache sin TTL porque un job stoppeado queda asi para siempre. Pero se pone TTL de 2h para que luego libere la memoria
|
|
35
|
+
stoppedJobsCache = new NodeCache({
|
|
36
|
+
stdTTL: NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL * HOUR
|
|
37
|
+
});
|
|
38
|
+
|
|
17
39
|
NotificationsApi = function () {
|
|
18
40
|
function NotificationsApi(_ref) {
|
|
19
41
|
var notificationApiUrl = _ref.notificationApiUrl,
|
|
20
42
|
token = _ref.token,
|
|
21
|
-
jobId = _ref.jobId
|
|
43
|
+
jobId = _ref.jobId,
|
|
44
|
+
_ref$notificationApiA = _ref.notificationApiAsyncUrl,
|
|
45
|
+
notificationApiAsyncUrl = _ref$notificationApiA === undefined ? DEFAULT_NOTIFICATIONS_API_ASYNC_URL : _ref$notificationApiA;
|
|
22
46
|
|
|
23
47
|
_classCallCheck(this, NotificationsApi);
|
|
24
48
|
|
|
25
49
|
this.success = this.success.bind(this);
|
|
26
50
|
this.fail = this.fail.bind(this);
|
|
51
|
+
this.jobIsStopped = this.jobIsStopped.bind(this);
|
|
52
|
+
this._jobIsStopped = this._jobIsStopped.bind(this);
|
|
53
|
+
this._fetchJob = this._fetchJob.bind(this);
|
|
54
|
+
this._doFetchJob = this._doFetchJob.bind(this);
|
|
55
|
+
this._retryViaAsyncOrIgnore = this._retryViaAsyncOrIgnore.bind(this);
|
|
27
56
|
this._makeRequest = this._makeRequest.bind(this);
|
|
57
|
+
this._shouldUseCachedValue = this._shouldUseCachedValue.bind(this);
|
|
28
58
|
this.notificationApiUrl = notificationApiUrl;
|
|
29
59
|
this.token = token;
|
|
30
60
|
this.jobId = jobId;
|
|
61
|
+
this.notificationApiAsyncUrl = notificationApiAsyncUrl;
|
|
31
62
|
}
|
|
32
63
|
|
|
33
64
|
_createClass(NotificationsApi, [{
|
|
34
65
|
key: "success",
|
|
35
|
-
value: function success(
|
|
66
|
+
value: function success(response, options) {
|
|
36
67
|
var _this = this;
|
|
37
68
|
|
|
38
|
-
var
|
|
69
|
+
var __makeRequest, __retryRequest, statusCode;
|
|
70
|
+
statusCode = response.statusCode;
|
|
39
71
|
|
|
40
|
-
|
|
72
|
+
__makeRequest = function __makeRequest() {
|
|
41
73
|
return _this._makeRequest({
|
|
42
74
|
statusCode: statusCode,
|
|
43
75
|
success: true
|
|
76
|
+
}, options);
|
|
77
|
+
};
|
|
78
|
+
__retryRequest = function __retryRequest() {
|
|
79
|
+
return _this.success(response, {
|
|
80
|
+
useAsyncApi: true
|
|
44
81
|
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}).catchReturn();
|
|
82
|
+
};
|
|
83
|
+
return this._retryViaAsyncOrIgnore(__makeRequest, __retryRequest, options);
|
|
48
84
|
}
|
|
49
85
|
}, {
|
|
50
86
|
key: "fail",
|
|
51
|
-
value: function fail(
|
|
87
|
+
value: function fail(response, options) {
|
|
52
88
|
var _this2 = this;
|
|
53
89
|
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
var __makeRequest, __retryRequest, error, message, request, statusCode;
|
|
91
|
+
statusCode = response.statusCode;
|
|
92
|
+
error = response.error;
|
|
93
|
+
request = response.request;
|
|
57
94
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
message = _.get(error, "message");
|
|
95
|
+
message = _.get(error, "message");
|
|
96
|
+
__makeRequest = function __makeRequest() {
|
|
61
97
|
return _this2._makeRequest({
|
|
62
98
|
statusCode: statusCode,
|
|
63
99
|
success: false,
|
|
64
100
|
message: message,
|
|
65
101
|
request: request
|
|
102
|
+
}, options);
|
|
103
|
+
};
|
|
104
|
+
__retryRequest = function __retryRequest() {
|
|
105
|
+
return _this2.fail(response, {
|
|
106
|
+
useAsyncApi: true
|
|
66
107
|
});
|
|
67
|
-
}
|
|
108
|
+
};
|
|
109
|
+
return this._retryViaAsyncOrIgnore(__makeRequest, __retryRequest, options);
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "jobIsStopped",
|
|
113
|
+
value: function jobIsStopped() {
|
|
114
|
+
var _this3 = this;
|
|
115
|
+
|
|
116
|
+
var cachedStoppedJob;
|
|
117
|
+
cachedStoppedJob = stoppedJobsCache.get(this.jobId);
|
|
118
|
+
if (this._shouldUseCachedValue(cachedStoppedJob)) {
|
|
119
|
+
return Promise.resolve(cachedStoppedJob);
|
|
120
|
+
}
|
|
121
|
+
return this._jobIsStopped().tap(function (jobIsStopped) {
|
|
122
|
+
if (jobIsStopped) {
|
|
123
|
+
return stoppedJobsCache.set(_this3.jobId, jobIsStopped);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "_jobIsStopped",
|
|
129
|
+
value: function _jobIsStopped() {
|
|
130
|
+
return this._fetchJob().then(function (job) {
|
|
131
|
+
return job.stopped;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "_fetchJob",
|
|
136
|
+
value: function _fetchJob() {
|
|
137
|
+
var _this4 = this;
|
|
138
|
+
|
|
139
|
+
var cachedJob;
|
|
140
|
+
cachedJob = jobsCache.get(this.jobId);
|
|
141
|
+
if (this._shouldUseCachedValue(cachedJob)) {
|
|
142
|
+
return Promise.resolve(cachedJob);
|
|
143
|
+
}
|
|
144
|
+
return this._doFetchJob().tap(function (job) {
|
|
145
|
+
return jobsCache.set(_this4.jobId, job);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "_doFetchJob",
|
|
150
|
+
value: function _doFetchJob() {
|
|
151
|
+
var _this5 = this;
|
|
152
|
+
|
|
153
|
+
var __fetchJob;
|
|
154
|
+
__fetchJob = function __fetchJob() {
|
|
155
|
+
return requestPromise({
|
|
156
|
+
url: _this5.notificationApiUrl + "/jobs/" + _this5.jobId,
|
|
157
|
+
method: "GET",
|
|
158
|
+
headers: {
|
|
159
|
+
authorization: _this5.token
|
|
160
|
+
},
|
|
161
|
+
json: true
|
|
162
|
+
}).promise();
|
|
163
|
+
};
|
|
164
|
+
return retry(__fetchJob, {
|
|
165
|
+
throw_original: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "_retryViaAsyncOrIgnore",
|
|
170
|
+
value: function _retryViaAsyncOrIgnore(makeRequest, retryRequest) {
|
|
171
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
172
|
+
|
|
173
|
+
return retry(makeRequest, {
|
|
174
|
+
throw_original: true,
|
|
68
175
|
max_tries: 3
|
|
176
|
+
}).catch(function (e) {
|
|
177
|
+
if (options.useAsyncApi) {
|
|
178
|
+
throw e;
|
|
179
|
+
}
|
|
180
|
+
console.log("Error sending status to notifications-api. Retrying via notifications-api-async");
|
|
181
|
+
return retryRequest();
|
|
69
182
|
}).catchReturn();
|
|
70
183
|
}
|
|
71
184
|
}, {
|
|
72
185
|
key: "_makeRequest",
|
|
73
186
|
value: function _makeRequest(body) {
|
|
74
|
-
|
|
75
|
-
|
|
187
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
188
|
+
useAsyncApi = _ref2.useAsyncApi;
|
|
189
|
+
|
|
190
|
+
var url;
|
|
191
|
+
url = useAsyncApi ? this.notificationApiAsyncUrl : this.notificationApiUrl;
|
|
192
|
+
return requestPromise({
|
|
193
|
+
url: url + "/jobs/" + this.jobId + "/operations",
|
|
76
194
|
method: "POST",
|
|
77
195
|
headers: {
|
|
78
196
|
authorization: this.token
|
|
@@ -80,6 +198,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
80
198
|
json: body
|
|
81
199
|
});
|
|
82
200
|
}
|
|
201
|
+
}, {
|
|
202
|
+
key: "_shouldUseCachedValue",
|
|
203
|
+
value: function _shouldUseCachedValue(value) {
|
|
204
|
+
return process.env.NODE_ENV !== "test" && value != null;
|
|
205
|
+
}
|
|
83
206
|
}]);
|
|
84
207
|
|
|
85
208
|
return NotificationsApi;
|
|
@@ -4,7 +4,7 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
// Generated by CoffeeScript 2.
|
|
7
|
+
// Generated by CoffeeScript 2.7.0
|
|
8
8
|
(function () {
|
|
9
9
|
var MaxRetriesProcessor;
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
// Generated by CoffeeScript 2.
|
|
3
|
+
// Generated by CoffeeScript 2.7.0
|
|
4
4
|
(function () {
|
|
5
5
|
var RequestProcessor, _, _normalizeHeaders, builderRequest;
|
|
6
6
|
|
|
@@ -43,8 +43,10 @@
|
|
|
43
43
|
module.exports = function (_ref3) {
|
|
44
44
|
var apiUrl = _ref3.apiUrl,
|
|
45
45
|
_ref3$fullResponse = _ref3.fullResponse,
|
|
46
|
-
fullResponse = _ref3$fullResponse === undefined ? false : _ref3$fullResponse
|
|
46
|
+
fullResponse = _ref3$fullResponse === undefined ? false : _ref3$fullResponse,
|
|
47
|
+
silentErrors = _ref3.silentErrors,
|
|
48
|
+
nonRetryable = _ref3.nonRetryable;
|
|
47
49
|
|
|
48
|
-
return RequestProcessor(builderRequest(apiUrl, fullResponse));
|
|
50
|
+
return RequestProcessor(builderRequest(apiUrl, fullResponse), { silentErrors: silentErrors, nonRetryable: nonRetryable });
|
|
49
51
|
};
|
|
50
52
|
}).call(undefined);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
// Generated by CoffeeScript 2.
|
|
3
|
+
// Generated by CoffeeScript 2.7.0
|
|
4
4
|
(function () {
|
|
5
5
|
var MESSAGE_PROPERTIES, NonRetryableError, Promise, RequestError, StatusCodeError, _, __isIncludedInStatusesError, _safeParse, _type, errorConditions, httpStatus, request;
|
|
6
6
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
4
|
+
|
|
5
|
+
// Generated by CoffeeScript 2.7.0
|
|
6
|
+
(function () {
|
|
7
|
+
var OAuthApi, Promise, _, _companyId;
|
|
8
|
+
|
|
9
|
+
_ = require("lodash");
|
|
10
|
+
|
|
11
|
+
OAuthApi = require("../services/oAuthApi");
|
|
12
|
+
|
|
13
|
+
Promise = require("bluebird");
|
|
14
|
+
|
|
15
|
+
_companyId = function _companyId(method, token) {
|
|
16
|
+
var decoded;
|
|
17
|
+
if (method !== "Basic") {
|
|
18
|
+
return new OAuthApi(token).companyId();
|
|
19
|
+
}
|
|
20
|
+
decoded = Buffer.from(token, "base64").toString();
|
|
21
|
+
return _.split(decoded, ":")[0];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
user: function user(_ref) {
|
|
26
|
+
var HeadersForRequest = _ref.message.HeadersForRequest;
|
|
27
|
+
|
|
28
|
+
var auth, method, token;
|
|
29
|
+
auth = _.find(HeadersForRequest, {
|
|
30
|
+
Key: "Authorization"
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _$get$split = _.get(auth, "Value", "").split(" ");
|
|
34
|
+
|
|
35
|
+
var _$get$split2 = _slicedToArray(_$get$split, 2);
|
|
36
|
+
|
|
37
|
+
method = _$get$split2[0];
|
|
38
|
+
token = _$get$split2[1];
|
|
39
|
+
|
|
40
|
+
return _companyId(method, token);
|
|
41
|
+
},
|
|
42
|
+
resource: function resource(_ref2, resourceGetter) {
|
|
43
|
+
var message = _ref2.message;
|
|
44
|
+
|
|
45
|
+
if (_.isFunction(resourceGetter)) {
|
|
46
|
+
return resourceGetter(message);
|
|
47
|
+
} else {
|
|
48
|
+
return _.get(message, "Resource");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}).call(undefined);
|
package/lib/senders/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
// Generated by CoffeeScript 2.
|
|
3
|
+
// Generated by CoffeeScript 2.7.0
|
|
4
4
|
(function () {
|
|
5
5
|
module.exports = {
|
|
6
6
|
MeliSender: require("./meli.sender"),
|
|
7
|
-
ProductecaSender: require("./producteca.sender")
|
|
7
|
+
ProductecaSender: require("./producteca.sender"),
|
|
8
|
+
AsyncProductecaSender: require("./async.producteca.sender")
|
|
8
9
|
};
|
|
9
10
|
}).call(undefined);
|