qdone 2.0.29-alpha → 2.0.30-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/commonjs/src/cache.js +22 -93
- package/commonjs/src/cloudWatch.js +65 -111
- package/commonjs/src/consumer.js +135 -237
- package/commonjs/src/defaults.js +11 -11
- package/commonjs/src/enqueue.js +311 -503
- package/commonjs/src/exponentialBackoff.js +39 -110
- package/commonjs/src/idleQueues.js +255 -396
- package/commonjs/src/monitor.js +42 -115
- package/commonjs/src/qrlCache.js +80 -162
- package/commonjs/src/scheduler/jobExecutor.js +305 -363
- package/commonjs/src/scheduler/queueManager.js +111 -198
- package/commonjs/src/scheduler/systemMonitor.js +24 -28
- package/commonjs/src/sqs.js +58 -141
- package/package.json +2 -2
- package/src/consumer.js +3 -5
- package/src/defaults.js +3 -3
- package/src/enqueue.js +1 -1
- package/src/scheduler/jobExecutor.js +77 -33
- package/src/scheduler/queueManager.js +1 -1
package/commonjs/src/monitor.js
CHANGED
|
@@ -2,100 +2,42 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Multi-queue monitoring functionaliry
|
|
4
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
42
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
43
|
-
if (ar || !(i in from)) {
|
|
44
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
45
|
-
ar[i] = from[i];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
|
-
};
|
|
50
5
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
6
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
7
|
};
|
|
53
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
9
|
exports.getAggregateData = exports.interpretWildcard = exports.monitor = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
10
|
+
const sqs_js_1 = require("./sqs.js");
|
|
11
|
+
const cloudWatch_js_1 = require("./cloudWatch.js");
|
|
12
|
+
const defaults_js_1 = require("./defaults.js");
|
|
13
|
+
const debug_1 = __importDefault(require("debug"));
|
|
14
|
+
const debug = (0, debug_1.default)('sd:utils:qmonitor:index');
|
|
60
15
|
/**
|
|
61
16
|
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
62
17
|
*/
|
|
63
|
-
function monitor(queue, save, options) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!save) return [3 /*break*/, 3];
|
|
75
|
-
if (opt.verbose)
|
|
76
|
-
process.stderr.write('Saving to CloudWatch...');
|
|
77
|
-
return [4 /*yield*/, (0, cloudWatch_js_1.putAggregateData)(data)];
|
|
78
|
-
case 2:
|
|
79
|
-
_a.sent();
|
|
80
|
-
if (opt.verbose)
|
|
81
|
-
process.stderr.write('done\n');
|
|
82
|
-
_a.label = 3;
|
|
83
|
-
case 3: return [2 /*return*/];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
18
|
+
async function monitor(queue, save, options) {
|
|
19
|
+
const opt = (0, defaults_js_1.getOptionsWithDefaults)(options);
|
|
20
|
+
const data = await getAggregateData(queue);
|
|
21
|
+
console.log(data);
|
|
22
|
+
if (save) {
|
|
23
|
+
if (opt.verbose)
|
|
24
|
+
process.stderr.write('Saving to CloudWatch...');
|
|
25
|
+
await (0, cloudWatch_js_1.putAggregateData)(data);
|
|
26
|
+
if (opt.verbose)
|
|
27
|
+
process.stderr.write('done\n');
|
|
28
|
+
}
|
|
87
29
|
}
|
|
88
30
|
exports.monitor = monitor;
|
|
89
31
|
/**
|
|
90
32
|
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
91
33
|
*/
|
|
92
34
|
function interpretWildcard(queueName) {
|
|
93
|
-
|
|
35
|
+
const [prefix, suffix] = queueName.split('*');
|
|
94
36
|
// Strip anything that could cause backreferences
|
|
95
|
-
|
|
96
|
-
|
|
37
|
+
const safeSuffix = (suffix || '').replace(/[^a-zA-Z0-9_.]+/g, '').replace(/\./g, '\\.');
|
|
38
|
+
const suffixRegex = new RegExp(`${safeSuffix}$`);
|
|
97
39
|
// debug({ prefix, suffix, safeSuffix, suffixRegex })
|
|
98
|
-
return { prefix
|
|
40
|
+
return { prefix, suffix, safeSuffix, suffixRegex };
|
|
99
41
|
}
|
|
100
42
|
exports.interpretWildcard = interpretWildcard;
|
|
101
43
|
/**
|
|
@@ -105,44 +47,29 @@ exports.interpretWildcard = interpretWildcard;
|
|
|
105
47
|
* - ApproximateNumberOfMessagesDelayed: Sum
|
|
106
48
|
* - ApproximateNumberOfMessagesNotVisible: Sum
|
|
107
49
|
*/
|
|
108
|
-
function getAggregateData(queueName) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
case 2:
|
|
124
|
-
data = _c.sent();
|
|
125
|
-
total = { totalQueues: 0, contributingQueueNames: new Set() };
|
|
126
|
-
for (_i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
127
|
-
_b = data_1[_i], queue = _b.queue, result = _b.result;
|
|
128
|
-
// debug({ row })
|
|
129
|
-
total.totalQueues++;
|
|
130
|
-
for (key in result.Attributes) {
|
|
131
|
-
newAtrribute = parseInt(result.Attributes[key], 10);
|
|
132
|
-
if (newAtrribute > 0) {
|
|
133
|
-
total.contributingQueueNames.add(queue);
|
|
134
|
-
total[key] = (total[key] || 0) + newAtrribute;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// debug({ total })
|
|
139
|
-
// convert set to array
|
|
140
|
-
total.contributingQueueNames = __spreadArray([], total.contributingQueueNames.values(), true);
|
|
141
|
-
total.queueName = queueName;
|
|
142
|
-
return [2 /*return*/, total];
|
|
50
|
+
async function getAggregateData(queueName) {
|
|
51
|
+
const { prefix, suffixRegex } = interpretWildcard(queueName);
|
|
52
|
+
const qrls = await (0, sqs_js_1.getMatchingQueues)(prefix, suffixRegex);
|
|
53
|
+
// debug({ qrls })
|
|
54
|
+
const data = await (0, sqs_js_1.getQueueAttributes)(qrls);
|
|
55
|
+
// debug({ data })
|
|
56
|
+
const total = { totalQueues: 0, contributingQueueNames: new Set() };
|
|
57
|
+
for (const { queue, result } of data) {
|
|
58
|
+
// debug({ row })
|
|
59
|
+
total.totalQueues++;
|
|
60
|
+
for (const key in result.Attributes) {
|
|
61
|
+
const newAtrribute = parseInt(result.Attributes[key], 10);
|
|
62
|
+
if (newAtrribute > 0) {
|
|
63
|
+
total.contributingQueueNames.add(queue);
|
|
64
|
+
total[key] = (total[key] || 0) + newAtrribute;
|
|
143
65
|
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// debug({ total })
|
|
69
|
+
// convert set to array
|
|
70
|
+
total.contributingQueueNames = [...total.contributingQueueNames.values()];
|
|
71
|
+
total.queueName = queueName;
|
|
72
|
+
return total;
|
|
146
73
|
}
|
|
147
74
|
exports.getAggregateData = getAggregateData;
|
|
148
75
|
debug('loaded');
|
package/commonjs/src/qrlCache.js
CHANGED
|
@@ -3,64 +3,28 @@
|
|
|
3
3
|
* A cache for maintaining queue urls. Avoids having to call the GetQueueUrl
|
|
4
4
|
* api too often.
|
|
5
5
|
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
-
function step(op) {
|
|
20
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
22
|
-
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;
|
|
23
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
-
switch (op[0]) {
|
|
25
|
-
case 0: case 1: t = op; break;
|
|
26
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
-
default:
|
|
30
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
-
if (t[2]) _.ops.pop();
|
|
35
|
-
_.trys.pop(); continue;
|
|
36
|
-
}
|
|
37
|
-
op = body.call(thisArg, _);
|
|
38
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
8
|
};
|
|
45
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
10
|
exports.getQnameUrlPairs = exports.getMatchingQueues = exports.ingestQRLs = exports.qrlCacheInvalidate = exports.qrlCacheSet = exports.qrlCacheGet = exports.qrlCacheClear = exports.normalizeDLQName = exports.normalizeFailQueueName = exports.normalizeQueueName = exports.fifoSuffix = void 0;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
11
|
+
const url_1 = require("url");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
14
|
+
const sqs_js_1 = require("./sqs.js");
|
|
15
|
+
const debug_1 = __importDefault(require("debug"));
|
|
16
|
+
const debug = (0, debug_1.default)('qdone:qrlCache');
|
|
53
17
|
// The actual cache is shared across callers.
|
|
54
|
-
|
|
18
|
+
const qcache = new Map();
|
|
55
19
|
//
|
|
56
20
|
// Normalizes a queue name to end with .fifo if opt.fifo is set
|
|
57
21
|
//
|
|
58
22
|
exports.fifoSuffix = '.fifo';
|
|
59
23
|
function normalizeQueueName(qname, opt) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
24
|
+
const hasFifo = qname.endsWith(exports.fifoSuffix);
|
|
25
|
+
const needsFifo = opt.fifo && qname.slice(-1) !== '*';
|
|
26
|
+
const needsPrefix = !qname.startsWith(opt.prefix);
|
|
27
|
+
const base = hasFifo ? qname.slice(0, -exports.fifoSuffix.length) : qname;
|
|
64
28
|
return (needsPrefix ? opt.prefix : '') + base + (needsFifo ? exports.fifoSuffix : '');
|
|
65
29
|
}
|
|
66
30
|
exports.normalizeQueueName = normalizeQueueName;
|
|
@@ -68,10 +32,10 @@ exports.normalizeQueueName = normalizeQueueName;
|
|
|
68
32
|
// Normalizes fail queue name, appending both --fail-suffix and .fifo depending on opt
|
|
69
33
|
//
|
|
70
34
|
function normalizeFailQueueName(fqname, opt) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
debug({ fqname
|
|
74
|
-
|
|
35
|
+
const newopt = Object.assign({}, opt, { fifo: false });
|
|
36
|
+
const base = normalizeQueueName(fqname, newopt); // strip fifo
|
|
37
|
+
debug({ fqname, base, opt });
|
|
38
|
+
const needsFail = !base.endsWith(opt.failSuffix);
|
|
75
39
|
return base + (needsFail ? opt.failSuffix : '') + (opt.fifo ? exports.fifoSuffix : '');
|
|
76
40
|
}
|
|
77
41
|
exports.normalizeFailQueueName = normalizeFailQueueName;
|
|
@@ -79,9 +43,9 @@ exports.normalizeFailQueueName = normalizeFailQueueName;
|
|
|
79
43
|
// Normalizes dlq queue name, appending both --dlq-suffix and .fifo depending on opt
|
|
80
44
|
//
|
|
81
45
|
function normalizeDLQName(dqname, opt) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
46
|
+
const newopt = Object.assign({}, opt, { fifo: false });
|
|
47
|
+
const base = normalizeQueueName(dqname, newopt); // strip fifo
|
|
48
|
+
const needsDead = !base.endsWith(opt.dlqSuffix);
|
|
85
49
|
return base + (needsDead ? opt.dlqSuffix : '') + (opt.fifo ? exports.fifoSuffix : '');
|
|
86
50
|
}
|
|
87
51
|
exports.normalizeDLQName = normalizeDLQName;
|
|
@@ -96,32 +60,22 @@ exports.qrlCacheClear = qrlCacheClear;
|
|
|
96
60
|
// Get QRL (Queue URL)
|
|
97
61
|
// Returns a promise for the queue name
|
|
98
62
|
//
|
|
99
|
-
function qrlCacheGet(qname) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case 1:
|
|
116
|
-
result = _a.sent();
|
|
117
|
-
qrl = result.QueueUrl;
|
|
118
|
-
// debug('getQueueUrl returned', data)
|
|
119
|
-
qcache.set(qname, qrl);
|
|
120
|
-
// debug('qcache', Object.keys(qcache), 'get', qname, ' => ', qcache[qname])
|
|
121
|
-
return [2 /*return*/, qrl];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
63
|
+
async function qrlCacheGet(qname) {
|
|
64
|
+
debug('get', qname, qcache);
|
|
65
|
+
if (qcache.has(qname))
|
|
66
|
+
return qcache.get(qname);
|
|
67
|
+
const client = (0, sqs_js_1.getSQSClient)();
|
|
68
|
+
const input = { QueueName: qname };
|
|
69
|
+
const cmd = new client_sqs_1.GetQueueUrlCommand(input);
|
|
70
|
+
// debug({ cmd })
|
|
71
|
+
const result = await client.send(cmd);
|
|
72
|
+
// debug('result', result)
|
|
73
|
+
// if (!result) throw new Error(`No such queue ${qname}`)
|
|
74
|
+
const { QueueUrl: qrl } = result;
|
|
75
|
+
// debug('getQueueUrl returned', data)
|
|
76
|
+
qcache.set(qname, qrl);
|
|
77
|
+
// debug('qcache', Object.keys(qcache), 'get', qname, ' => ', qcache[qname])
|
|
78
|
+
return qrl;
|
|
125
79
|
}
|
|
126
80
|
exports.qrlCacheGet = qrlCacheGet;
|
|
127
81
|
//
|
|
@@ -146,13 +100,12 @@ exports.qrlCacheInvalidate = qrlCacheInvalidate;
|
|
|
146
100
|
// Extracts queue names from an array of QRLs and immediately updates the cache.
|
|
147
101
|
//
|
|
148
102
|
function ingestQRLs(qrls) {
|
|
149
|
-
|
|
103
|
+
const pairs = [];
|
|
150
104
|
debug('ingestQRLs', qrls);
|
|
151
|
-
for (
|
|
152
|
-
|
|
153
|
-
var qname = (0, path_1.basename)((new url_1.URL(qrl)).pathname);
|
|
105
|
+
for (const qrl of qrls) {
|
|
106
|
+
const qname = (0, path_1.basename)((new url_1.URL(qrl)).pathname);
|
|
154
107
|
qrlCacheSet(qname, qrl);
|
|
155
|
-
pairs.push({ qname
|
|
108
|
+
pairs.push({ qname, qrl });
|
|
156
109
|
// debug('qcache', Object.keys(qcache), 'ingestQRLs', qname, ' => ', qcache[qname])
|
|
157
110
|
}
|
|
158
111
|
return pairs;
|
|
@@ -161,90 +114,55 @@ exports.ingestQRLs = ingestQRLs;
|
|
|
161
114
|
/**
|
|
162
115
|
* Returns qrls for queues matching the given prefix and regex.
|
|
163
116
|
*/
|
|
164
|
-
function getMatchingQueues(prefix, nextToken) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
case 1:
|
|
179
|
-
result = _f.sent();
|
|
180
|
-
debug({ result: result });
|
|
181
|
-
_a = result || {}, qrls = _a.QueueUrls, keepGoing = _a.NextToken;
|
|
182
|
-
debug({ qrls: qrls, keepGoing: keepGoing });
|
|
183
|
-
if (!keepGoing) return [3 /*break*/, 3];
|
|
184
|
-
_c = (_b = (_e = (qrls || [])).push).apply;
|
|
185
|
-
_d = [_e];
|
|
186
|
-
return [4 /*yield*/, getMatchingQueues(prefix, keepGoing)];
|
|
187
|
-
case 2:
|
|
188
|
-
_c.apply(_b, _d.concat([_f.sent()]));
|
|
189
|
-
_f.label = 3;
|
|
190
|
-
case 3: return [2 /*return*/, qrls || []];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
117
|
+
async function getMatchingQueues(prefix, nextToken) {
|
|
118
|
+
debug('getMatchingQueues', prefix, nextToken);
|
|
119
|
+
const input = { QueueNamePrefix: prefix, MaxResults: 1000 };
|
|
120
|
+
if (nextToken)
|
|
121
|
+
input.NextToken = nextToken;
|
|
122
|
+
const client = (0, sqs_js_1.getSQSClient)();
|
|
123
|
+
const command = new client_sqs_1.ListQueuesCommand(input);
|
|
124
|
+
const result = await client.send(command);
|
|
125
|
+
debug({ result });
|
|
126
|
+
const { QueueUrls: qrls, NextToken: keepGoing } = result || {};
|
|
127
|
+
debug({ qrls, keepGoing });
|
|
128
|
+
if (keepGoing)
|
|
129
|
+
(qrls || []).push(...await getMatchingQueues(prefix, keepGoing));
|
|
130
|
+
return qrls || [];
|
|
194
131
|
}
|
|
195
132
|
exports.getMatchingQueues = getMatchingQueues;
|
|
196
133
|
//
|
|
197
134
|
// Resolves into a flattened aray of {qname: ..., qrl: ...} objects.
|
|
198
135
|
//
|
|
199
|
-
function getQnameUrlPairs(qnames, opt) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return [2 /*return*/, ingestQRLs(queues)];
|
|
224
|
-
}
|
|
225
|
-
return [3 /*break*/, 5];
|
|
226
|
-
case 2:
|
|
227
|
-
_b.trys.push([2, 4, , 5]);
|
|
228
|
-
_a = { qname: qname };
|
|
229
|
-
return [4 /*yield*/, qrlCacheGet(qname)];
|
|
230
|
-
case 3: return [2 /*return*/, (_a.qrl = _b.sent(), _a)];
|
|
231
|
-
case 4:
|
|
232
|
-
err_1 = _b.sent();
|
|
233
|
-
if (!(err_1 instanceof client_sqs_1.QueueDoesNotExist))
|
|
234
|
-
throw err_1;
|
|
235
|
-
return [3 /*break*/, 5];
|
|
236
|
-
case 5: return [2 /*return*/];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
242
|
-
case 1:
|
|
243
|
-
results = _a.sent();
|
|
244
|
-
return [2 /*return*/, ([].concat.apply([], results)).filter(function (r) { return r; })];
|
|
136
|
+
async function getQnameUrlPairs(qnames, opt) {
|
|
137
|
+
const promises = qnames.map(async function getQueueUrlOrUrls(qname) {
|
|
138
|
+
if (qname.slice(-1) === '*') {
|
|
139
|
+
// Wildcard queues support
|
|
140
|
+
const prefix = qname.slice(0, -1);
|
|
141
|
+
const queues = await getMatchingQueues(prefix);
|
|
142
|
+
debug('listQueues return', queues);
|
|
143
|
+
if (opt.fifo) {
|
|
144
|
+
// Remove non-fifo queues
|
|
145
|
+
const filteredQueues = queues.filter(url => url.slice(-exports.fifoSuffix.length) === exports.fifoSuffix);
|
|
146
|
+
return ingestQRLs(filteredQueues);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return ingestQRLs(queues);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Normal, non wildcard queue support
|
|
154
|
+
try {
|
|
155
|
+
return { qname, qrl: await qrlCacheGet(qname) };
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
if (!(err instanceof client_sqs_1.QueueDoesNotExist))
|
|
159
|
+
throw err;
|
|
245
160
|
}
|
|
246
|
-
}
|
|
161
|
+
}
|
|
247
162
|
});
|
|
163
|
+
// Flatten nested results
|
|
164
|
+
const results = await Promise.all(promises);
|
|
165
|
+
return ([].concat.apply([], results)).filter(r => r);
|
|
248
166
|
}
|
|
249
167
|
exports.getQnameUrlPairs = getQnameUrlPairs;
|
|
250
168
|
debug('loaded');
|