UNPKG

4.54 kBJavaScriptView Raw
1"use strict";
2
3var _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
5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7// Generated by CoffeeScript 2.5.1
8(function () {
9 var 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
23 var _require2 = require("./senders");
24
25 MeliSender = _require2.MeliSender;
26 ProductecaSender = _require2.ProductecaSender;
27
28
29 ProcessorBuilder = function () {
30 function ProcessorBuilder() {
31 _classCallCheck(this, ProcessorBuilder);
32
33 this.source = UnknownSource;
34 this.listeners = [];
35 }
36
37 _createClass(ProcessorBuilder, [{
38 key: "withSource",
39 value: function withSource(source) {
40 this.source = source;
41 return this;
42 }
43 }, {
44 key: "withSender",
45 value: function withSender(sender) {
46 this.sender = sender;
47 return this;
48 }
49 }, {
50 key: "withTimeout",
51 value: function withTimeout(timeout) {
52 this.timeout = timeout;
53 return this;
54 }
55 }, {
56 key: "withApm",
57 value: function withApm(apm) {
58 this.apm = apm;
59 return this;
60 }
61 }, {
62 key: "withDelayObserver",
63 value: function withDelayObserver(opts) {
64 return this.withListeners(this.source.delayObserver(opts));
65 }
66 }, {
67 key: "withDeadLetterSucceeded",
68 value: function withDeadLetterSucceeded(opts) {
69 if (this.sender == null) {
70 throw new Error("Sender is required");
71 }
72 return this.withListeners(this.source.deadLetterSucceeded(_.defaults(opts, { sender: this.sender })));
73 }
74 }, {
75 key: "withDidLastRetry",
76 value: function withDidLastRetry(opts) {
77 if (this.sender == null) {
78 throw new Error("Sender is required");
79 }
80 return this.withListeners(this.source.didLastRetry(_.defaults(opts, { sender: this.sender })));
81 }
82 }, {
83 key: "fromServiceBus",
84 value: function fromServiceBus() {
85 return this.withSource(ServiceBusSource);
86 }
87 }, {
88 key: "fromQueue",
89 value: function fromQueue() {
90 return this.withSource(QueueSource);
91 }
92 }, {
93 key: "fromMeli",
94 value: function fromMeli() {
95 return this.withSender(MeliSender);
96 }
97 }, {
98 key: "fromProducteca",
99 value: function fromProducteca() {
100 return this.withSender(ProductecaSender);
101 }
102 }, {
103 key: "withFunction",
104 value: function withFunction(command) {
105 this.command = command;
106 return this;
107 }
108 }, {
109 key: "withLogging",
110 value: function withLogging() {
111 return this.withListeners(logger);
112 }
113 }, {
114 key: "withListeners",
115 value: function withListeners() {
116 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
117 args[_key] = arguments[_key];
118 }
119
120 this.listeners = _.concat(this.listeners, args);
121 return this;
122 }
123 }, {
124 key: "build",
125 value: function build() {
126 var processor;
127 processor = new Processor({
128 source: this.source,
129 runner: this.command,
130 timeout: this.timeout,
131 apm: this.apm
132 });
133 _.forEach(this.listeners, function (listener) {
134 return listener.listenTo(processor);
135 });
136 return processor;
137 }
138 }], [{
139 key: "create",
140 value: function create() {
141 return new this();
142 }
143 }]);
144
145 return ProcessorBuilder;
146 }();
147
148 module.exports = ProcessorBuilder;
149}).call(undefined);
\No newline at end of file