UNPKG

4.39 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.4.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: "withDelayObserver",
57 value: function withDelayObserver(opts) {
58 return this.withListeners(this.source.delayObserver(opts));
59 }
60 }, {
61 key: "withDeadLetterSucceeded",
62 value: function withDeadLetterSucceeded(opts) {
63 if (this.sender == null) {
64 throw new Error("Sender is required");
65 }
66 return this.withListeners(this.source.deadLetterSucceeded(_.defaults(opts, { sender: this.sender })));
67 }
68 }, {
69 key: "withDidLastRetry",
70 value: function withDidLastRetry(opts) {
71 if (this.sender == null) {
72 throw new Error("Sender is required");
73 }
74 return this.withListeners(this.source.didLastRetry(_.defaults(opts, { sender: this.sender })));
75 }
76 }, {
77 key: "fromServiceBus",
78 value: function fromServiceBus() {
79 return this.withSource(ServiceBusSource);
80 }
81 }, {
82 key: "fromQueue",
83 value: function fromQueue() {
84 return this.withSource(QueueSource);
85 }
86 }, {
87 key: "fromMeli",
88 value: function fromMeli() {
89 return this.withSender(MeliSender);
90 }
91 }, {
92 key: "fromProducteca",
93 value: function fromProducteca() {
94 return this.withSender(ProductecaSender);
95 }
96 }, {
97 key: "withFunction",
98 value: function withFunction(command) {
99 this.command = command;
100 return this;
101 }
102 }, {
103 key: "withLogging",
104 value: function withLogging() {
105 return this.withListeners(logger);
106 }
107 }, {
108 key: "withListeners",
109 value: function withListeners() {
110 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
111 args[_key] = arguments[_key];
112 }
113
114 this.listeners = _.concat(this.listeners, args);
115 return this;
116 }
117 }, {
118 key: "build",
119 value: function build() {
120 var processor;
121 processor = new Processor({
122 source: this.source,
123 runner: this.command,
124 timeout: this.timeout
125 });
126 _.forEach(this.listeners, function (listener) {
127 return listener.listenTo(processor);
128 });
129 return processor;
130 }
131 }], [{
132 key: "create",
133 value: function create() {
134 return new this();
135 }
136 }]);
137
138 return ProcessorBuilder;
139 }();
140
141 module.exports = ProcessorBuilder;
142}).call(undefined);
\No newline at end of file