qdone 1.7.0 → 2.0.0-alpha

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/README.md CHANGED
@@ -425,6 +425,14 @@ Options
425
425
  -f, --fifo Create new queues as FIFOs
426
426
  -g, --group-id string FIFO Group ID to use for all messages enqueued in current command. Defaults to an string unique to this invocation.
427
427
  --group-id-per-message Use a unique Group ID for every message, even messages in the same batch.
428
+ --deduplication-id string A Message Deduplication ID to give SQS when sending a message. Use this
429
+ option if you are managing retries outside of qdone, and make sure the ID is
430
+ the same for each retry in the deduplication window. Defaults to a string
431
+ unique to this invocation.
432
+ -d, --delay number Delays delivery of each message by the given number of seconds (up to 900 seconds,
433
+ or 15 minutes). Defaults to immediate delivery (no delay).
434
+ --dlq-after number Sends messages from the failed queue to a dead letter queue after this many failures. [default: 3]
435
+ --dlq-suffix string Suffix to append to each queue to generate DLQ name [default: _dead]
428
436
  --prefix string Prefix to place at the front of each SQS queue name [default: qdone_]
429
437
  --fail-suffix string Suffix to append to each queue to generate fail queue name [default: _failed]
430
438
  --region string AWS region for Queues [default: us-east-1]
@@ -478,4 +486,4 @@ If a queue name ends with the * (wildcard) character, worker will listen on all
478
486
  -q, --quiet Turn on production logging. Automatically set if stderr is not a tty.
479
487
  -v, --verbose Turn on verbose output. Automatically set if stderr is a tty.
480
488
  -V, --version Show version number
481
- --help Print full help message.
489
+ --help Print full help message.
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DoNotProcess = exports.requestShutdown = exports.processMessages = exports.enqueueBatch = exports.enqueue = void 0;
4
+ var enqueue_js_1 = require("./src/enqueue.js");
5
+ Object.defineProperty(exports, "enqueue", { enumerable: true, get: function () { return enqueue_js_1.enqueue; } });
6
+ Object.defineProperty(exports, "enqueueBatch", { enumerable: true, get: function () { return enqueue_js_1.enqueueBatch; } });
7
+ var consumer_js_1 = require("./src/consumer.js");
8
+ Object.defineProperty(exports, "processMessages", { enumerable: true, get: function () { return consumer_js_1.processMessages; } });
9
+ Object.defineProperty(exports, "requestShutdown", { enumerable: true, get: function () { return consumer_js_1.requestShutdown; } });
10
+ Object.defineProperty(exports, "DoNotProcess", { enumerable: true, get: function () { return consumer_js_1.DoNotProcess; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.setCache = exports.getCache = exports.shutdownCache = exports.getCacheClient = void 0;
58
+ var ioredis_1 = __importDefault(require("ioredis"));
59
+ var url_1 = require("url");
60
+ var debug_1 = __importDefault(require("debug"));
61
+ var debug = (0, debug_1.default)('qdone:cache');
62
+ var UsageError = /** @class */ (function (_super) {
63
+ __extends(UsageError, _super);
64
+ function UsageError() {
65
+ return _super !== null && _super.apply(this, arguments) || this;
66
+ }
67
+ return UsageError;
68
+ }(Error));
69
+ var client;
70
+ /**
71
+ * Internal function to setup redis client. Parses URI to figure out
72
+ * how to connect.
73
+ */
74
+ function getCacheClient(opt) {
75
+ if (client) {
76
+ return client;
77
+ }
78
+ else if (opt.cacheUri) {
79
+ var url = new url_1.URL(opt.cacheUri);
80
+ if (url.protocol === 'redis:') {
81
+ client = new ioredis_1.default(url.toString());
82
+ }
83
+ else if (url.protocol === 'redis-cluster:') {
84
+ url.protocol = 'redis:';
85
+ client = new ioredis_1.default.Cluster([url.toString()], { slotsRefreshInterval: 60 * 1000 });
86
+ }
87
+ else {
88
+ throw new UsageError("Only redis:// or redis-cluster:// URLs are currently supported. Got: ".concat(url.protocol));
89
+ }
90
+ return client;
91
+ }
92
+ else {
93
+ throw new UsageError('Caching requires the --cache-uri option');
94
+ }
95
+ }
96
+ exports.getCacheClient = getCacheClient;
97
+ function shutdownCache() {
98
+ if (client)
99
+ client.quit();
100
+ client = undefined;
101
+ }
102
+ exports.shutdownCache = shutdownCache;
103
+ /**
104
+ * Returns a promise for the item. Resolves to false if cache is empty, object
105
+ * if it is found.
106
+ */
107
+ function getCache(key, opt) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var client, cacheKey, result;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ client = getCacheClient(opt);
114
+ cacheKey = opt.cachePrefix + key;
115
+ debug({ action: 'getCache', cacheKey: cacheKey });
116
+ return [4 /*yield*/, client.get(cacheKey)];
117
+ case 1:
118
+ result = _a.sent();
119
+ debug({ action: 'getCache got', cacheKey: cacheKey, result: result });
120
+ return [2 /*return*/, result ? JSON.parse(result) : undefined];
121
+ }
122
+ });
123
+ });
124
+ }
125
+ exports.getCache = getCache;
126
+ /**
127
+ * Returns a promise for the status. Encodes object as JSON
128
+ */
129
+ function setCache(key, value, opt) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var client, encoded, cacheKey;
132
+ return __generator(this, function (_a) {
133
+ client = getCacheClient(opt);
134
+ encoded = JSON.stringify(value);
135
+ cacheKey = opt.cachePrefix + key;
136
+ debug({ action: 'setCache', cacheKey: cacheKey, value: value });
137
+ return [2 /*return*/, client.setex(cacheKey, opt.cacheTtlSeconds, encoded)];
138
+ });
139
+ });
140
+ }
141
+ exports.setCache = setCache;
142
+ debug('loaded');
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ /**
3
+ * Functions that deal with CloudWatch
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ var __generator = (this && this.__generator) || function (thisArg, body) {
15
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
16
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17
+ function verb(n) { return function (v) { return step([n, v]); }; }
18
+ function step(op) {
19
+ if (f) throw new TypeError("Generator is already executing.");
20
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
21
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22
+ if (y = 0, t) op = [op[0] & 2, t.value];
23
+ switch (op[0]) {
24
+ case 0: case 1: t = op; break;
25
+ case 4: _.label++; return { value: op[1], done: false };
26
+ case 5: _.label++; y = op[1]; op = [0]; continue;
27
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
28
+ default:
29
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
30
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
31
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
32
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
33
+ if (t[2]) _.ops.pop();
34
+ _.trys.pop(); continue;
35
+ }
36
+ op = body.call(thisArg, _);
37
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
38
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
39
+ }
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.putAggregateData = exports.setCloudWatchClient = exports.getCloudWatchClient = void 0;
46
+ var client_cloudwatch_1 = require("@aws-sdk/client-cloudwatch");
47
+ var debug_1 = __importDefault(require("debug"));
48
+ var debug = (0, debug_1.default)('qdone:cloudWatch');
49
+ /**
50
+ * Utility function to return an instantiated, shared CloudWatchClient.
51
+ */
52
+ var client;
53
+ function getCloudWatchClient() {
54
+ if (client)
55
+ return client;
56
+ client = new client_cloudwatch_1.CloudWatchClient();
57
+ return client;
58
+ }
59
+ exports.getCloudWatchClient = getCloudWatchClient;
60
+ /**
61
+ * Utility function to set the client explicitly, used in testing.
62
+ */
63
+ function setCloudWatchClient(explicitClient) {
64
+ client = explicitClient;
65
+ }
66
+ exports.setCloudWatchClient = setCloudWatchClient;
67
+ /**
68
+ * Takes data in the form returned by getAggregageData() and pushes it to
69
+ * CloudWatch metrics under the given queueName.
70
+ *
71
+ * @param queueName {String} - The name of the wildcard queue these metrics are for.
72
+ * @param total {Object} - returned object from getAggregateData()
73
+ */
74
+ function putAggregateData(total, timestamp) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var client, now, input, command, response;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ client = getCloudWatchClient();
81
+ now = timestamp || new Date();
82
+ input = {
83
+ Namespace: 'qmonitor',
84
+ MetricData: [
85
+ {
86
+ MetricName: 'totalQueues',
87
+ Dimensions: [{
88
+ Name: 'queueName',
89
+ Value: total.queueName
90
+ }],
91
+ Timestamp: now,
92
+ Value: total.totalQueues,
93
+ Unit: 'Count'
94
+ },
95
+ {
96
+ MetricName: 'contributingQueueCount',
97
+ Dimensions: [{
98
+ Name: 'queueName',
99
+ Value: total.queueName
100
+ }],
101
+ Timestamp: now,
102
+ Value: total.contributingQueueNames.length,
103
+ Unit: 'Count'
104
+ },
105
+ {
106
+ MetricName: 'ApproximateNumberOfMessages',
107
+ Dimensions: [{
108
+ Name: 'queueName',
109
+ Value: total.queueName
110
+ }],
111
+ Timestamp: now,
112
+ Value: total.ApproximateNumberOfMessages || 0,
113
+ Unit: 'Count'
114
+ },
115
+ {
116
+ MetricName: 'ApproximateNumberOfMessagesDelayed',
117
+ Dimensions: [{
118
+ Name: 'queueName',
119
+ Value: total.queueName
120
+ }],
121
+ Timestamp: now,
122
+ Value: total.ApproximateNumberOfMessagesDelayed || 0,
123
+ Unit: 'Count'
124
+ },
125
+ {
126
+ MetricName: 'ApproximateNumberOfMessagesNotVisible',
127
+ Dimensions: [{
128
+ Name: 'queueName',
129
+ Value: total.queueName
130
+ }],
131
+ Timestamp: now,
132
+ Value: total.ApproximateNumberOfMessagesNotVisible || 0,
133
+ Unit: 'Count'
134
+ }
135
+ ]
136
+ };
137
+ command = new client_cloudwatch_1.PutMetricDataCommand(input);
138
+ return [4 /*yield*/, client.send(command)];
139
+ case 1:
140
+ response = _a.sent();
141
+ debug({ response: response });
142
+ return [2 /*return*/];
143
+ }
144
+ });
145
+ });
146
+ }
147
+ exports.putAggregateData = putAggregateData;
148
+ debug('loaded');