qdone 2.0.18-alpha → 2.0.20-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/index.js +3 -1
- package/commonjs/src/consumer.js +8 -5
- package/commonjs/src/defaults.js +3 -0
- package/commonjs/src/monitor.js +148 -0
- package/commonjs/src/scheduler/jobExecutor.js +0 -1
- package/commonjs/src/sqs.js +22 -2
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/consumer.js +7 -4
- package/src/defaults.js +3 -0
- package/src/monitor.js +16 -0
- package/src/scheduler/jobExecutor.js +0 -1
- package/src/sqs.js +21 -4
- package/commonjs/src/sentry.js +0 -111
- package/npm-shrinkwrap.json +0 -16001
package/commonjs/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestShutdown = exports.processMessages = exports.enqueueBatch = exports.enqueue = void 0;
|
|
3
|
+
exports.monitor = exports.requestShutdown = exports.processMessages = exports.enqueueBatch = exports.enqueue = void 0;
|
|
4
4
|
var enqueue_js_1 = require("./src/enqueue.js");
|
|
5
5
|
Object.defineProperty(exports, "enqueue", { enumerable: true, get: function () { return enqueue_js_1.enqueue; } });
|
|
6
6
|
Object.defineProperty(exports, "enqueueBatch", { enumerable: true, get: function () { return enqueue_js_1.enqueueBatch; } });
|
|
7
7
|
var consumer_js_1 = require("./src/consumer.js");
|
|
8
8
|
Object.defineProperty(exports, "processMessages", { enumerable: true, get: function () { return consumer_js_1.processMessages; } });
|
|
9
9
|
Object.defineProperty(exports, "requestShutdown", { enumerable: true, get: function () { return consumer_js_1.requestShutdown; } });
|
|
10
|
+
var monitor_js_1 = require("./src/monitor.js");
|
|
11
|
+
Object.defineProperty(exports, "monitor", { enumerable: true, get: function () { return monitor_js_1.monitor; } });
|
package/commonjs/src/consumer.js
CHANGED
|
@@ -118,7 +118,7 @@ exports.getMessages = getMessages;
|
|
|
118
118
|
//
|
|
119
119
|
function processMessages(queues, callback, options) {
|
|
120
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var opt, lastLatency, systemMonitor, jobExecutor, queueManager, delayTimeout, delay, activeQrls, maxReturnCount, listen, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, jobsLeft, _i, _a, _b, qname, qrl, maxMessages;
|
|
121
|
+
var opt, lastLatency, systemMonitor, jobExecutor, queueManager, delayTimeout, delay, activeQrls, maxReturnCount, listen, allowedJobs, maxLatency, freeMemory, totalMemory, memoryThreshold, latency, latencyFactor, freememFactor, targetJobs, jobsLeft, _i, _a, _b, qname, qrl, maxMessages;
|
|
122
122
|
var _this = this;
|
|
123
123
|
return __generator(this, function (_c) {
|
|
124
124
|
switch (_c.label) {
|
|
@@ -209,16 +209,19 @@ function processMessages(queues, callback, options) {
|
|
|
209
209
|
if (!!shutdownRequested) return [3 /*break*/, 3];
|
|
210
210
|
allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.activeJobCount() - maxReturnCount);
|
|
211
211
|
maxLatency = 100;
|
|
212
|
+
freeMemory = (0, os_1.freemem)();
|
|
213
|
+
totalMemory = (0, os_1.totalmem)();
|
|
214
|
+
memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
|
|
212
215
|
latency = systemMonitor.getLatency() || 10;
|
|
213
216
|
latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
214
217
|
;
|
|
215
|
-
freememFactor = Math.min(1, Math.max(0,
|
|
218
|
+
freememFactor = Math.min(1, Math.max(0, freeMemory / memoryThreshold));
|
|
216
219
|
targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor);
|
|
217
220
|
jobsLeft = targetJobs;
|
|
218
|
-
debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
221
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory: freeMemory, totalMemory: totalMemory, memoryThreshold: memoryThreshold, maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
219
222
|
for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
|
|
220
223
|
_b = _a[_i], qname = _b.qname, qrl = _b.qrl;
|
|
221
|
-
debug({ evaluating: { qname
|
|
224
|
+
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
222
225
|
if (jobsLeft <= 0 || activeQrls.has(qrl))
|
|
223
226
|
continue;
|
|
224
227
|
maxMessages = Math.min(10, jobsLeft);
|
|
@@ -227,7 +230,7 @@ function processMessages(queues, callback, options) {
|
|
|
227
230
|
if (opt.verbose) {
|
|
228
231
|
console.error(chalk_1.default.blue('Listening on: '), qname);
|
|
229
232
|
}
|
|
230
|
-
debug({ listenedTo: { qname
|
|
233
|
+
// debug({ listenedTo: { qname, maxMessages, jobsLeft } })
|
|
231
234
|
}
|
|
232
235
|
return [4 /*yield*/, delay(1000)];
|
|
233
236
|
case 2:
|
package/commonjs/src/defaults.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.defaults = Object.freeze({
|
|
|
37
37
|
archive: false,
|
|
38
38
|
activeOnly: false,
|
|
39
39
|
maxConcurrentJobs: 100,
|
|
40
|
+
maxMemoryPercent: 70,
|
|
40
41
|
// Idle Queues
|
|
41
42
|
idleFor: 60,
|
|
42
43
|
delete: false,
|
|
@@ -95,6 +96,7 @@ function getOptionsWithDefaults(options) {
|
|
|
95
96
|
activeOnly: options.activeOnly || options['active-only'] || exports.defaults.activeOnly,
|
|
96
97
|
includeFailed: options.includeFailed || options['include-failed'] || exports.defaults.includeFailed,
|
|
97
98
|
maxConcurrentJobs: options.maxConcurrentJobs || exports.defaults.maxConcurrentJobs,
|
|
99
|
+
maxMemoryPercent: options.maxMemoryPercent || exports.defaults.maxMemoryPercent,
|
|
98
100
|
// Idle Queues
|
|
99
101
|
idleFor: options.idleFor || options['idle-for'] || exports.defaults.idleFor,
|
|
100
102
|
delete: options.delete || exports.defaults.delete,
|
|
@@ -112,6 +114,7 @@ function getOptionsWithDefaults(options) {
|
|
|
112
114
|
opt.waitTime = validateInteger(opt, 'waitTime');
|
|
113
115
|
opt.killAfter = validateInteger(opt, 'killAfter');
|
|
114
116
|
opt.maxConcurrentJobs = validateInteger(opt, 'maxConcurrentJobs');
|
|
117
|
+
opt.maxMemoryPercent = validateInteger(opt, 'maxMemoryPercent');
|
|
115
118
|
opt.idleFor = validateInteger(opt, 'idleFor');
|
|
116
119
|
return opt;
|
|
117
120
|
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Multi-queue monitoring functionaliry
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.getAggregateData = exports.interpretWildcard = exports.monitor = void 0;
|
|
55
|
+
var sqs_js_1 = require("./sqs.js");
|
|
56
|
+
var cloudWatch_js_1 = require("./cloudWatch.js");
|
|
57
|
+
var defaults_js_1 = require("./defaults.js");
|
|
58
|
+
var debug_1 = __importDefault(require("debug"));
|
|
59
|
+
var debug = (0, debug_1.default)('sd:utils:qmonitor:index');
|
|
60
|
+
/**
|
|
61
|
+
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
62
|
+
*/
|
|
63
|
+
function monitor(queue, save, options) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var opt, data;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
opt = (0, defaults_js_1.getOptionsWithDefaults)(options);
|
|
70
|
+
return [4 /*yield*/, getAggregateData(queue)];
|
|
71
|
+
case 1:
|
|
72
|
+
data = _a.sent();
|
|
73
|
+
console.log(data);
|
|
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
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.monitor = monitor;
|
|
89
|
+
/**
|
|
90
|
+
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
91
|
+
*/
|
|
92
|
+
function interpretWildcard(queueName) {
|
|
93
|
+
var _a = queueName.split('*'), prefix = _a[0], suffix = _a[1];
|
|
94
|
+
// Strip anything that could cause backreferences
|
|
95
|
+
var safeSuffix = (suffix || '').replace(/[^a-zA-Z0-9_.]+/g, '').replace(/\./g, '\\.');
|
|
96
|
+
var suffixRegex = new RegExp("".concat(safeSuffix, "$"));
|
|
97
|
+
// debug({ prefix, suffix, safeSuffix, suffixRegex })
|
|
98
|
+
return { prefix: prefix, suffix: suffix, safeSuffix: safeSuffix, suffixRegex: suffixRegex };
|
|
99
|
+
}
|
|
100
|
+
exports.interpretWildcard = interpretWildcard;
|
|
101
|
+
/**
|
|
102
|
+
* Aggregates inmportant attributes across queues and reports a summary.
|
|
103
|
+
* Attributes:
|
|
104
|
+
* - ApproximateNumberOfMessages: Sum
|
|
105
|
+
* - ApproximateNumberOfMessagesDelayed: Sum
|
|
106
|
+
* - ApproximateNumberOfMessagesNotVisible: Sum
|
|
107
|
+
*/
|
|
108
|
+
function getAggregateData(queueName) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var _a, prefix, suffixRegex, qrls, data, total, _i, data_1, _b, queue, result, key, newAtrribute;
|
|
111
|
+
return __generator(this, function (_c) {
|
|
112
|
+
switch (_c.label) {
|
|
113
|
+
case 0:
|
|
114
|
+
_a = interpretWildcard(queueName), prefix = _a.prefix, suffixRegex = _a.suffixRegex;
|
|
115
|
+
return [4 /*yield*/, (0, sqs_js_1.getMatchingQueues)(prefix, suffixRegex)
|
|
116
|
+
// debug({ qrls })
|
|
117
|
+
];
|
|
118
|
+
case 1:
|
|
119
|
+
qrls = _c.sent();
|
|
120
|
+
return [4 /*yield*/, (0, sqs_js_1.getQueueAttributes)(qrls)
|
|
121
|
+
// debug({ data })
|
|
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];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
exports.getAggregateData = getAggregateData;
|
|
148
|
+
debug('loaded');
|
|
@@ -47,7 +47,6 @@ exports.JobExecutor = void 0;
|
|
|
47
47
|
var client_sqs_1 = require("@aws-sdk/client-sqs");
|
|
48
48
|
var chalk_1 = __importDefault(require("chalk"));
|
|
49
49
|
var debug_1 = __importDefault(require("debug"));
|
|
50
|
-
var sentry_js_1 = require("../sentry.js");
|
|
51
50
|
var sqs_js_1 = require("../sqs.js");
|
|
52
51
|
var debug = (0, debug_1.default)('qdone:jobExecutor');
|
|
53
52
|
var maxJobSeconds = 12 * 60 * 60;
|
package/commonjs/src/sqs.js
CHANGED
|
@@ -131,18 +131,38 @@ function getQueueAttributes(qrls) {
|
|
|
131
131
|
var command = new client_sqs_1.GetQueueAttributesCommand(input);
|
|
132
132
|
// debug({ input, command })
|
|
133
133
|
promises.push((function () { return __awaiter(_this, void 0, void 0, function () {
|
|
134
|
-
var queue, result;
|
|
134
|
+
var queue, result, e_1;
|
|
135
135
|
return __generator(this, function (_a) {
|
|
136
136
|
switch (_a.label) {
|
|
137
137
|
case 0:
|
|
138
138
|
queue = (0, path_1.basename)(qrl);
|
|
139
|
+
_a.label = 1;
|
|
140
|
+
case 1:
|
|
141
|
+
_a.trys.push([1, 3, , 4]);
|
|
139
142
|
return [4 /*yield*/, client.send(command)
|
|
140
143
|
// debug({ queue, result })
|
|
141
144
|
];
|
|
142
|
-
case
|
|
145
|
+
case 2:
|
|
143
146
|
result = _a.sent();
|
|
144
147
|
// debug({ queue, result })
|
|
145
148
|
return [2 /*return*/, { queue: queue, result: result }];
|
|
149
|
+
case 3:
|
|
150
|
+
e_1 = _a.sent();
|
|
151
|
+
if (e_1 instanceof client_sqs_1.QueueDoesNotExist) {
|
|
152
|
+
// For queues that have been deleted in the meantime for whatever
|
|
153
|
+
// reason, just show as having no messages instead of failing the
|
|
154
|
+
// whole batch
|
|
155
|
+
return [2 /*return*/, {
|
|
156
|
+
queue: queue,
|
|
157
|
+
Attributes: {
|
|
158
|
+
ApproximateNumberOfMessages: '0',
|
|
159
|
+
ApproximateNumberOfMessagesNotVisible: '0',
|
|
160
|
+
ApproximateNumberOfMessagesDelayed: '0'
|
|
161
|
+
}
|
|
162
|
+
}];
|
|
163
|
+
}
|
|
164
|
+
throw e_1;
|
|
165
|
+
case 4: return [2 /*return*/];
|
|
146
166
|
}
|
|
147
167
|
});
|
|
148
168
|
}); })());
|
package/index.js
CHANGED
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -116,14 +116,17 @@ export async function processMessages (queues, callback, options) {
|
|
|
116
116
|
// Figure out how we are running
|
|
117
117
|
const allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.activeJobCount() - maxReturnCount)
|
|
118
118
|
const maxLatency = 100
|
|
119
|
+
const freeMemory = freemem()
|
|
120
|
+
const totalMemory = totalmem()
|
|
121
|
+
const memoryThreshold = totalMemory * opt.maxMemoryPercent / 100
|
|
119
122
|
const latency = systemMonitor.getLatency() || 10
|
|
120
123
|
const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
121
|
-
const freememFactor = Math.min(1, Math.max(0,
|
|
124
|
+
const freememFactor = Math.min(1, Math.max(0, freeMemory / memoryThreshold))
|
|
122
125
|
const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
|
|
123
126
|
let jobsLeft = targetJobs
|
|
124
|
-
debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
127
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
125
128
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
126
|
-
debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
129
|
+
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
127
130
|
if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
|
|
128
131
|
const maxMessages = Math.min(10, jobsLeft)
|
|
129
132
|
listen(qname, qrl, maxMessages)
|
|
@@ -131,7 +134,7 @@ export async function processMessages (queues, callback, options) {
|
|
|
131
134
|
if (opt.verbose) {
|
|
132
135
|
console.error(chalk.blue('Listening on: '), qname)
|
|
133
136
|
}
|
|
134
|
-
debug({ listenedTo: { qname, maxMessages, jobsLeft } })
|
|
137
|
+
// debug({ listenedTo: { qname, maxMessages, jobsLeft } })
|
|
135
138
|
}
|
|
136
139
|
await delay(1000)
|
|
137
140
|
}
|
package/src/defaults.js
CHANGED
|
@@ -37,6 +37,7 @@ export const defaults = Object.freeze({
|
|
|
37
37
|
archive: false,
|
|
38
38
|
activeOnly: false,
|
|
39
39
|
maxConcurrentJobs: 100,
|
|
40
|
+
maxMemoryPercent: 70,
|
|
40
41
|
|
|
41
42
|
// Idle Queues
|
|
42
43
|
idleFor: 60,
|
|
@@ -101,6 +102,7 @@ export function getOptionsWithDefaults (options) {
|
|
|
101
102
|
activeOnly: options.activeOnly || options['active-only'] || defaults.activeOnly,
|
|
102
103
|
includeFailed: options.includeFailed || options['include-failed'] || defaults.includeFailed,
|
|
103
104
|
maxConcurrentJobs: options.maxConcurrentJobs || defaults.maxConcurrentJobs,
|
|
105
|
+
maxMemoryPercent: options.maxMemoryPercent || defaults.maxMemoryPercent,
|
|
104
106
|
|
|
105
107
|
// Idle Queues
|
|
106
108
|
idleFor: options.idleFor || options['idle-for'] || defaults.idleFor,
|
|
@@ -121,6 +123,7 @@ export function getOptionsWithDefaults (options) {
|
|
|
121
123
|
opt.waitTime = validateInteger(opt, 'waitTime')
|
|
122
124
|
opt.killAfter = validateInteger(opt, 'killAfter')
|
|
123
125
|
opt.maxConcurrentJobs = validateInteger(opt, 'maxConcurrentJobs')
|
|
126
|
+
opt.maxMemoryPercent = validateInteger(opt, 'maxMemoryPercent')
|
|
124
127
|
opt.idleFor = validateInteger(opt, 'idleFor')
|
|
125
128
|
|
|
126
129
|
return opt
|
package/src/monitor.js
CHANGED
|
@@ -3,9 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { getMatchingQueues, getQueueAttributes } from './sqs.js'
|
|
6
|
+
import { putAggregateData } from './cloudWatch.js'
|
|
7
|
+
import { getOptionsWithDefaults } from './defaults.js'
|
|
6
8
|
import Debug from 'debug'
|
|
7
9
|
const debug = Debug('sd:utils:qmonitor:index')
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
13
|
+
*/
|
|
14
|
+
export async function monitor (queue, save, options) {
|
|
15
|
+
const opt = getOptionsWithDefaults(options)
|
|
16
|
+
const data = await getAggregateData(queue)
|
|
17
|
+
console.log(data)
|
|
18
|
+
if (save) {
|
|
19
|
+
if (opt.verbose) process.stderr.write('Saving to CloudWatch...')
|
|
20
|
+
await putAggregateData(data)
|
|
21
|
+
if (opt.verbose) process.stderr.write('done\n')
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Splits a queue name with a single wildcard into prefix and suffix regex.
|
|
11
27
|
*/
|
|
@@ -8,7 +8,6 @@ import { ChangeMessageVisibilityBatchCommand, DeleteMessageBatchCommand } from '
|
|
|
8
8
|
import chalk from 'chalk'
|
|
9
9
|
import Debug from 'debug'
|
|
10
10
|
|
|
11
|
-
import { withSentry } from '../sentry.js'
|
|
12
11
|
import { getSQSClient } from '../sqs.js'
|
|
13
12
|
|
|
14
13
|
const debug = Debug('qdone:jobExecutor')
|
package/src/sqs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Functions that deal with SQS
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { SQSClient, ListQueuesCommand, GetQueueAttributesCommand } from '@aws-sdk/client-sqs'
|
|
5
|
+
import { SQSClient, ListQueuesCommand, GetQueueAttributesCommand, QueueDoesNotExist } from '@aws-sdk/client-sqs'
|
|
6
6
|
import { basename } from 'path'
|
|
7
7
|
import Debug from 'debug'
|
|
8
8
|
const debug = Debug('qdone:sqs')
|
|
@@ -62,9 +62,26 @@ export async function getQueueAttributes (qrls) {
|
|
|
62
62
|
// debug({ input, command })
|
|
63
63
|
promises.push((async () => {
|
|
64
64
|
const queue = basename(qrl)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
try {
|
|
66
|
+
const result = await client.send(command)
|
|
67
|
+
// debug({ queue, result })
|
|
68
|
+
return { queue, result }
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (e instanceof QueueDoesNotExist) {
|
|
71
|
+
// For queues that have been deleted in the meantime for whatever
|
|
72
|
+
// reason, just show as having no messages instead of failing the
|
|
73
|
+
// whole batch
|
|
74
|
+
return {
|
|
75
|
+
queue,
|
|
76
|
+
Attributes: {
|
|
77
|
+
ApproximateNumberOfMessages: '0',
|
|
78
|
+
ApproximateNumberOfMessagesNotVisible: '0',
|
|
79
|
+
ApproximateNumberOfMessagesDelayed: '0'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw e
|
|
84
|
+
}
|
|
68
85
|
})())
|
|
69
86
|
}
|
|
70
87
|
return Promise.all(promises)
|
package/commonjs/src/sentry.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Routines for handling Sentry instrumentation
|
|
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.withSentry = void 0;
|
|
46
|
-
var debug_1 = __importDefault(require("debug"));
|
|
47
|
-
var node_1 = require("@sentry/node");
|
|
48
|
-
var debug = (0, debug_1.default)('qdone:sentry');
|
|
49
|
-
var sentryWasInit = false;
|
|
50
|
-
function withSentry(callback, opt, contexts) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
var result, err_1;
|
|
53
|
-
return __generator(this, function (_a) {
|
|
54
|
-
switch (_a.label) {
|
|
55
|
-
case 0:
|
|
56
|
-
debug({ withSentry: { callback: callback, opt: opt, contexts: contexts } });
|
|
57
|
-
// Bail if sentry isn't enabled
|
|
58
|
-
if (!opt.sentryDsn)
|
|
59
|
-
return [2 /*return*/, callback()
|
|
60
|
-
// Init sentry if it's not already
|
|
61
|
-
];
|
|
62
|
-
// Init sentry if it's not already
|
|
63
|
-
if (!sentryWasInit) {
|
|
64
|
-
(0, node_1.init)({ dsn: opt.sentryDsn, traceSampleRate: 0 });
|
|
65
|
-
sentryWasInit = true;
|
|
66
|
-
}
|
|
67
|
-
_a.label = 1;
|
|
68
|
-
case 1:
|
|
69
|
-
_a.trys.push([1, 3, , 5]);
|
|
70
|
-
return [4 /*yield*/, callback()];
|
|
71
|
-
case 2:
|
|
72
|
-
result = _a.sent();
|
|
73
|
-
debug({ result: result });
|
|
74
|
-
return [2 /*return*/, result];
|
|
75
|
-
case 3:
|
|
76
|
-
err_1 = _a.sent();
|
|
77
|
-
debug({ err: err_1 });
|
|
78
|
-
return [4 /*yield*/, (0, node_1.withScope)(function (scope) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
-
var key, stdout, stderr, sentryResult;
|
|
81
|
-
return __generator(this, function (_a) {
|
|
82
|
-
switch (_a.label) {
|
|
83
|
-
case 0:
|
|
84
|
-
scope.setContext('opt', opt);
|
|
85
|
-
if (contexts instanceof Object) {
|
|
86
|
-
for (key in contexts)
|
|
87
|
-
scope.setContext(key, contexts[key]);
|
|
88
|
-
if (err_1.stdout && err_1.stderr) {
|
|
89
|
-
stdout = err_1.stdout, stderr = err_1.stderr;
|
|
90
|
-
scope.setContext('IO', { stdout: stdout, stderr: stderr });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return [4 /*yield*/, (0, node_1.captureException)(err_1)];
|
|
94
|
-
case 1:
|
|
95
|
-
sentryResult = _a.sent();
|
|
96
|
-
debug({ sentryResult: sentryResult });
|
|
97
|
-
return [2 /*return*/];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
})];
|
|
102
|
-
case 4:
|
|
103
|
-
_a.sent();
|
|
104
|
-
throw err_1;
|
|
105
|
-
case 5: return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
exports.withSentry = withSentry;
|
|
111
|
-
debug('loaded');
|