notification-processor 5.0.3 → 5.1.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/lib/exceptions/ignored.error.js +0 -27
  4. package/lib/exceptions/non.retryable.js +0 -27
  5. package/lib/index.js +0 -25
  6. package/lib/observers/delay.levels.js +0 -32
  7. package/lib/observers/incidentsApi.observer.js +0 -109
  8. package/lib/observers/logger.observer.js +0 -59
  9. package/lib/observers/monitoringCenter.observer.js +0 -234
  10. package/lib/observers/redis.observer.js +0 -90
  11. package/lib/processor.builder.js +0 -134
  12. package/lib/processor.js +0 -132
  13. package/lib/processors/deadletter.processor.js +0 -45
  14. package/lib/processors/job/index.js +0 -38
  15. package/lib/processors/job/job.processor.js +0 -150
  16. package/lib/processors/job/notification.api.js +0 -237
  17. package/lib/processors/maxRetries.processor.js +0 -88
  18. package/lib/processors/request.async.processor.js +0 -56
  19. package/lib/processors/request.processor.js +0 -114
  20. package/lib/processors/requestWithRetries.async.processor.js +0 -22
  21. package/lib/senders/async.producteca.sender.js +0 -145
  22. package/lib/senders/index.js +0 -10
  23. package/lib/senders/meli.sender.js +0 -46
  24. package/lib/senders/producteca.sender.js +0 -34
  25. package/lib/services/oAuthApi.js +0 -77
  26. package/lib/services/redis.js +0 -16
  27. package/lib/services/userIdTranslator.js +0 -111
  28. package/lib/sources/aws.sqs.source.js +0 -37
  29. package/lib/sources/index.js +0 -12
  30. package/lib/sources/queue.source.js +0 -26
  31. package/lib/sources/service.bus.source.js +0 -26
  32. package/lib/sources/table.source.js +0 -20
  33. package/lib/sources/unknown.source.js +0 -15
  34. package/lib/specHelpers/fixture.js +0 -29
  35. package/lib/specHelpers/redis.observer.mock.js +0 -65
@@ -1,134 +0,0 @@
1
- "use strict";
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- // Generated by CoffeeScript 2.7.0
8
- (function () {
9
- var AwsSQSSource, MeliSender, Processor, ProcessorBuilder, ProductecaSender, QueueSource, ServiceBusSource, UnknownSource, _, logger;
10
-
11
- _ = require("lodash");
12
-
13
- Processor = require("./processor");
14
-
15
- logger = require("./observers/logger.observer");
16
-
17
- var _require = require("./sources");
18
-
19
- UnknownSource = _require.UnknownSource;
20
- ServiceBusSource = _require.ServiceBusSource;
21
- QueueSource = _require.QueueSource;
22
- AwsSQSSource = _require.AwsSQSSource;
23
-
24
- var _require2 = require("./senders");
25
-
26
- MeliSender = _require2.MeliSender;
27
- ProductecaSender = _require2.ProductecaSender;
28
-
29
-
30
- ProcessorBuilder = function () {
31
- function ProcessorBuilder() {
32
- _classCallCheck(this, ProcessorBuilder);
33
-
34
- this.source = UnknownSource;
35
- this.listeners = [];
36
- }
37
-
38
- _createClass(ProcessorBuilder, [{
39
- key: "withSource",
40
- value: function withSource(source) {
41
- this.source = source;
42
- return this;
43
- }
44
- }, {
45
- key: "withSender",
46
- value: function withSender(sender) {
47
- this.sender = sender;
48
- return this;
49
- }
50
- }, {
51
- key: "withTimeout",
52
- value: function withTimeout(timeout) {
53
- this.timeout = timeout;
54
- return this;
55
- }
56
- }, {
57
- key: "withApm",
58
- value: function withApm(apm) {
59
- this.apm = apm;
60
- return this;
61
- }
62
- }, {
63
- key: "fromServiceBus",
64
- value: function fromServiceBus() {
65
- return this.withSource(ServiceBusSource);
66
- }
67
- }, {
68
- key: "fromAwsSQS",
69
- value: function fromAwsSQS() {
70
- return this.withSource(AwsSQSSource);
71
- }
72
- }, {
73
- key: "fromQueue",
74
- value: function fromQueue() {
75
- return this.withSource(QueueSource);
76
- }
77
- }, {
78
- key: "fromMeli",
79
- value: function fromMeli() {
80
- return this.withSender(MeliSender);
81
- }
82
- }, {
83
- key: "fromProducteca",
84
- value: function fromProducteca() {
85
- return this.withSender(ProductecaSender);
86
- }
87
- }, {
88
- key: "withFunction",
89
- value: function withFunction(command) {
90
- this.command = command;
91
- return this;
92
- }
93
- }, {
94
- key: "withLogging",
95
- value: function withLogging() {
96
- return this.withListeners(logger);
97
- }
98
- }, {
99
- key: "withListeners",
100
- value: function withListeners() {
101
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
102
- args[_key] = arguments[_key];
103
- }
104
-
105
- this.listeners = _.concat(this.listeners, args);
106
- return this;
107
- }
108
- }, {
109
- key: "build",
110
- value: function build() {
111
- var processor;
112
- processor = new Processor({
113
- source: this.source,
114
- runner: this.command,
115
- timeout: this.timeout,
116
- apm: this.apm
117
- });
118
- _.forEach(this.listeners, function (listener) {
119
- return listener.listenTo(processor);
120
- });
121
- return processor;
122
- }
123
- }], [{
124
- key: "create",
125
- value: function create() {
126
- return new this();
127
- }
128
- }]);
129
-
130
- return ProcessorBuilder;
131
- }();
132
-
133
- module.exports = ProcessorBuilder;
134
- }).call(undefined);
package/lib/processor.js DELETED
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
-
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
-
11
- // Generated by CoffeeScript 2.7.0
12
- (function () {
13
- var ENABLE_EVENTS,
14
- EventEmitter,
15
- IgnoredError,
16
- NonRetryable,
17
- Processor,
18
- Promise,
19
- _,
20
- newrelic,
21
- uuid,
22
- boundMethodCheck = function boundMethodCheck(instance, Constructor) {
23
- if (!(instance instanceof Constructor)) {
24
- throw new Error('Bound instance method accessed before binding');
25
- }
26
- };
27
-
28
- _ = require("lodash");
29
-
30
- NonRetryable = require("./exceptions/non.retryable");
31
-
32
- IgnoredError = require("./exceptions/ignored.error");
33
-
34
- EventEmitter = require("events");
35
-
36
- Promise = require("bluebird");
37
-
38
- uuid = require("uuid/v4");
39
-
40
- newrelic = _.once(function () {
41
- return require("newrelic");
42
- });
43
-
44
- ENABLE_EVENTS = process.env.ENABLE_EVENTS !== "false";
45
-
46
- module.exports = Processor = function (_EventEmitter) {
47
- _inherits(Processor, _EventEmitter);
48
-
49
- function Processor(_ref) {
50
- var source = _ref.source,
51
- runner = _ref.runner,
52
- timeout = _ref.timeout,
53
- apm = _ref.apm;
54
-
55
- _classCallCheck(this, Processor);
56
-
57
- var _this = _possibleConstructorReturn(this, (Processor.__proto__ || Object.getPrototypeOf(Processor)).call(this));
58
-
59
- _this.process = _this.process.bind(_this);
60
- _this._emitEvent = _this._emitEvent.bind(_this);
61
- _this.source = source;
62
- _this.runner = runner;
63
- _this.timeout = timeout;
64
- _this.apm = apm;
65
- return _this;
66
- }
67
-
68
- _createClass(Processor, [{
69
- key: "process",
70
- value: function process(context, raw) {
71
- var _this2 = this;
72
-
73
- var $promise, _isIgnoredError, execute, id, notification;
74
- boundMethodCheck(this, Processor);
75
- id = uuid();
76
- notification = this.source.newNotification({
77
- context: context,
78
- id: id,
79
- message: raw
80
- });
81
- this._emitEvent("started", { context: context, id: id, notification: notification });
82
- $promise = Promise.method(this.runner)(notification, context, id);
83
- if (this.timeout != null) {
84
- $promise = $promise.timeout(this.timeout, "processor timeout");
85
- }
86
- execute = function execute() {
87
- var ref;
88
- if (!((ref = _this2.apm) != null ? ref.active : void 0)) {
89
- return $promise;
90
- }
91
- return newrelic().startBackgroundTransaction(_this2.apm.transactionName, _this2.apm.group, function () {
92
- return $promise.tapCatch(function (err) {
93
- return newrelic().noticeError(new Error(JSON.stringify(_.omit(err.detail, "request.auth.pass"))));
94
- });
95
- });
96
- };
97
- _isIgnoredError = function _isIgnoredError(error) {
98
- return error instanceof IgnoredError;
99
- };
100
- execute().tap(function () {
101
- return _this2._emitEvent("successful", { context: context, id: id, notification: notification });
102
- }).catch(_isIgnoredError, function (error) {
103
- return _this2._emitEvent("successful", {
104
- context: context,
105
- id: id,
106
- notification: notification,
107
- warnings: [error]
108
- });
109
- }).catch(function (error) {
110
- if (!(error instanceof NonRetryable)) {
111
- throw error;
112
- }
113
- return _this2._emitEvent("unsuccessful_non_retryable", { context: context, id: id, notification: notification, error: error });
114
- }).tapCatch(function (error) {
115
- return _this2._emitEvent("unsuccessful", { context: context, id: id, notification: notification, error: error });
116
- }).finally(function () {
117
- return _this2._emitEvent("finished", { context: context, id: id, notification: notification });
118
- }).asCallback(context.done);
119
- }
120
- }, {
121
- key: "_emitEvent",
122
- value: function _emitEvent(eventName, value) {
123
- boundMethodCheck(this, Processor);
124
- if (ENABLE_EVENTS) {
125
- return this.emit(eventName, value);
126
- }
127
- }
128
- }]);
129
-
130
- return Processor;
131
- }(EventEmitter);
132
- }).call(undefined);
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
-
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
-
11
- // Generated by CoffeeScript 2.7.0
12
- (function () {
13
- var DeadletterProcessor, MaxRetriesProcessor, NonRetryable;
14
-
15
- MaxRetriesProcessor = require("./maxRetries.processor");
16
-
17
- NonRetryable = require("../exceptions/non.retryable");
18
-
19
- module.exports = DeadletterProcessor = function (_MaxRetriesProcessor) {
20
- _inherits(DeadletterProcessor, _MaxRetriesProcessor);
21
-
22
- function DeadletterProcessor() {
23
- _classCallCheck(this, DeadletterProcessor);
24
-
25
- return _possibleConstructorReturn(this, (DeadletterProcessor.__proto__ || Object.getPrototypeOf(DeadletterProcessor)).apply(this, arguments));
26
- }
27
-
28
- _createClass(DeadletterProcessor, [{
29
- key: "_onSuccess_",
30
- value: function _onSuccess_(notification, result) {}
31
- }, {
32
- key: "_sanitizeError_",
33
- value: function _sanitizeError_(err) {
34
- return err;
35
- }
36
- }, {
37
- key: "_onMaxRetryExceeded_",
38
- value: function _onMaxRetryExceeded_(notification, err) {
39
- throw new NonRetryable("Max retry exceeded", err);
40
- }
41
- }]);
42
-
43
- return DeadletterProcessor;
44
- }(MaxRetriesProcessor);
45
- }).call(undefined);
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- // Generated by CoffeeScript 2.7.0
4
- (function () {
5
- var JobProcessor, RequestAsyncProcessor, _;
6
-
7
- _ = require("lodash");
8
-
9
- JobProcessor = require("./job.processor");
10
-
11
- RequestAsyncProcessor = require("../request.async.processor");
12
-
13
- module.exports = function (_ref) {
14
- var apiUrl = _ref.apiUrl,
15
- notificationApiUrl = _ref.notificationApiUrl,
16
- maxRetries = _ref.maxRetries,
17
- _ref$nonRetryable = _ref.nonRetryable,
18
- nonRetryable = _ref$nonRetryable === undefined ? [400] : _ref$nonRetryable,
19
- _ref$silentErrors = _ref.silentErrors,
20
- silentErrors = _ref$silentErrors === undefined ? [] : _ref$silentErrors;
21
-
22
- var jobProcesor;
23
- jobProcesor = new JobProcessor({
24
- processor: RequestAsyncProcessor({
25
- apiUrl: apiUrl,
26
- fullResponse: true,
27
- silentErrors: silentErrors
28
- }),
29
- maxRetries: maxRetries,
30
- nonRetryable: nonRetryable,
31
- silentErrors: silentErrors,
32
- notificationApiUrl: notificationApiUrl
33
- });
34
- return function (it, context, executionId) {
35
- return jobProcesor.process(it, context, executionId);
36
- };
37
- };
38
- }).call(undefined);
@@ -1,150 +0,0 @@
1
- "use strict";
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
6
-
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
10
-
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
-
13
- // Generated by CoffeeScript 2.7.0
14
- (function () {
15
- var JobProcessor,
16
- MaxRetriesProcessor,
17
- NonRetryable,
18
- NotificationsApi,
19
- _,
20
- debug,
21
- request,
22
- boundMethodCheck = function boundMethodCheck(instance, Constructor) {
23
- if (!(instance instanceof Constructor)) {
24
- throw new Error('Bound instance method accessed before binding');
25
- }
26
- },
27
- indexOf = [].indexOf;
28
-
29
- _ = require("lodash");
30
-
31
- request = require("request-promise");
32
-
33
- MaxRetriesProcessor = require("../maxRetries.processor");
34
-
35
- NonRetryable = require("../../exceptions/non.retryable");
36
-
37
- NotificationsApi = require("./notification.api");
38
-
39
- debug = require("debug")("notification-processor:job-processor");
40
-
41
- module.exports = JobProcessor = function (_MaxRetriesProcessor) {
42
- _inherits(JobProcessor, _MaxRetriesProcessor);
43
-
44
- function JobProcessor(args) {
45
- _classCallCheck(this, JobProcessor);
46
-
47
- var _this = _possibleConstructorReturn(this, (JobProcessor.__proto__ || Object.getPrototypeOf(JobProcessor)).call(this, args));
48
-
49
- _this.process = _this.process.bind(_this);
50
- _this._onSuccess_ = _this._onSuccess_.bind(_this);
51
- _this._shouldRetry_ = _this._shouldRetry_.bind(_this);
52
- _this._sanitizeError_ = _this._sanitizeError_.bind(_this);
53
- _this._onMaxRetryExceeded_ = _this._onMaxRetryExceeded_.bind(_this);
54
- _this._notificationsApi = _this._notificationsApi.bind(_this);
55
- _this._ifJobIsNotStopped = _this._ifJobIsNotStopped.bind(_this);
56
- _this.notificationApiUrl = args.notificationApiUrl;
57
- _this.notificationApiAsyncUrl = args.notificationApiAsyncUrl;
58
- _this.nonRetryable = args.nonRetryable;
59
- _this.silentErrors = args.silentErrors;
60
- return _this;
61
- }
62
-
63
- _createClass(JobProcessor, [{
64
- key: "process",
65
- value: function process(notification, context, executionId) {
66
- var _this2 = this;
67
-
68
- boundMethodCheck(this, JobProcessor);
69
- return this._ifJobIsNotStopped(notification.message, function () {
70
- return _get(JobProcessor.prototype.__proto__ || Object.getPrototypeOf(JobProcessor.prototype), "process", _this2).call(_this2, notification, context, executionId).thenReturn();
71
- });
72
- }
73
- }, {
74
- key: "_onSuccess_",
75
- value: function _onSuccess_(_ref, _ref2) {
76
- var _this3 = this;
77
-
78
- var message = _ref.message;
79
- var statusCode = _ref2.statusCode;
80
-
81
- boundMethodCheck(this, JobProcessor);
82
- return this._ifJobIsNotStopped(message, function () {
83
- return _this3._notificationsApi(message).success({ message: message, statusCode: statusCode });
84
- });
85
- }
86
- }, {
87
- key: "_shouldRetry_",
88
- value: function _shouldRetry_(notification, err) {
89
- var ref, ref1, ref2;
90
- boundMethodCheck(this, JobProcessor);
91
- return _get(JobProcessor.prototype.__proto__ || Object.getPrototypeOf(JobProcessor.prototype), "_shouldRetry_", this).call(this, notification, err) && (ref = err != null ? (ref1 = err.detail) != null ? (ref2 = ref1.response) != null ? ref2.statusCode : void 0 : void 0 : void 0, indexOf.call(this.nonRetryable, ref) < 0);
92
- }
93
- }, {
94
- key: "_sanitizeError_",
95
- value: function _sanitizeError_(err) {
96
- boundMethodCheck(this, JobProcessor);
97
- return _.pick(err, ["statusCode", "error"]);
98
- }
99
- }, {
100
- key: "_onMaxRetryExceeded_",
101
- value: function _onMaxRetryExceeded_(_ref3, error) {
102
- var _this4 = this;
103
-
104
- var message = _ref3.message;
105
-
106
- var errorMessage;
107
- boundMethodCheck(this, JobProcessor);
108
- errorMessage = {
109
- message: message,
110
- statusCode: error.detail.response.statusCode,
111
- error: error,
112
- request: _.omit(error.detail.request, ["resolveWithFullResponse"])
113
- };
114
- return this._ifJobIsNotStopped(message, function () {
115
- return _this4._notificationsApi(message).fail(errorMessage).throw(new NonRetryable("Max retry exceeded", error));
116
- });
117
- }
118
- }, {
119
- key: "_notificationsApi",
120
- value: function _notificationsApi(_ref4) {
121
- var HeadersForRequest = _ref4.HeadersForRequest,
122
- JobId = _ref4.JobId;
123
-
124
- boundMethodCheck(this, JobProcessor);
125
- return new NotificationsApi({
126
- token: _.find(HeadersForRequest, {
127
- Key: "Authorization"
128
- }).Value,
129
- jobId: JobId,
130
- notificationApiUrl: this.notificationApiUrl,
131
- notificationApiAsyncUrl: this.notificationApiAsyncUrl
132
- });
133
- }
134
- }, {
135
- key: "_ifJobIsNotStopped",
136
- value: function _ifJobIsNotStopped(message, action) {
137
- boundMethodCheck(this, JobProcessor);
138
- return this._notificationsApi(message).jobIsStopped().then(function (jobIsStopped) {
139
- if (jobIsStopped) {
140
- console.log("job " + message.JobId + " is stopped, ignoring action");
141
- return Promise.resolve();
142
- }
143
- return action();
144
- });
145
- }
146
- }]);
147
-
148
- return JobProcessor;
149
- }(MaxRetriesProcessor);
150
- }).call(undefined);