qdone 2.0.27-alpha → 2.0.29-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.
@@ -183,7 +183,7 @@ function processMessages(queues, callback, options) {
183
183
  if (messages.length) {
184
184
  for (_i = 0, messages_1 = messages; _i < messages_1.length; _i++) {
185
185
  message = messages_1[_i];
186
- jobExecutor.executeJob(message, callback, qname, qrl, function () { return queueManager.updateIcehouse(qrl, true); });
186
+ jobExecutor.executeJob(message, callback, qname, qrl);
187
187
  }
188
188
  queueManager.updateIcehouse(qrl, false);
189
189
  }
@@ -231,7 +231,7 @@ function processMessages(queues, callback, options) {
231
231
  targetJobs = Math.round(allowedJobs * overallFactor);
232
232
  jobsLeft = targetJobs;
233
233
  if (opt.verbose) {
234
- console.error({ jobCount: jobExecutor.activeJobCount(), freeMemory: freeMemory, totalMemory: totalMemory, freememThreshold: freememThreshold, remainingMemory: remainingMemory, memoryThreshold: memoryThreshold, maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, oneMinuteLoad: oneMinuteLoad, loadPerCore: loadPerCore, loadFactor: loadFactor, overallFactor: overallFactor, targetJobs: targetJobs, activeQrls: activeQrls });
234
+ console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, jobCount: jobExecutor.activeJobCount(), allowedJobs: allowedJobs, maxLatency: maxLatency, latencyFactor: latencyFactor, freememFactor: freememFactor, loadFactor: loadFactor, overallFactor: overallFactor, targetJobs: targetJobs, activeQrls: activeQrls });
235
235
  }
236
236
  for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
237
237
  _b = _a[_i], qname = _b.qname, qrl = _b.qrl;
@@ -96,10 +96,10 @@ var JobExecutor = /** @class */ (function () {
96
96
  */
97
97
  JobExecutor.prototype.maintainVisibility = function () {
98
98
  return __awaiter(this, void 0, void 0, function () {
99
- var nextCheckInMs, start, jobsToExtendByQrl, jobsToDeleteByQrl, jobsToCleanup, i, job, jobRunTime, jobsToDelete, jobsToExtend, doubled, secondsUntilMax, _a, _b, _c, _i, qrl, jobsToExtend, entries, messageId, job, entry, input, result, count, _d, _e, _f, _g, qrl, jobsToDelete, entries, messageId, job, entry, input, result, count;
99
+ var nextCheckInMs, start, jobsToExtendByQrl, jobsToDeleteByQrl, jobsToCleanup, i, job, jobRunTime, jobsToDelete, jobsToExtend, doubled, secondsUntilMax, _a, _b, _c, _i, qrl, jobsToExtend, entries, messageId, job, entry, input, result, _d, _e, failed, count, _f, _g, _h, _j, qrl, jobsToDelete, entries, messageId, job, entry, input, result, _k, _l, failed, count;
100
100
  var _this = this;
101
- return __generator(this, function (_h) {
102
- switch (_h.label) {
101
+ return __generator(this, function (_m) {
102
+ switch (_m.label) {
103
103
  case 0:
104
104
  // Bail if we are shutting down
105
105
  if (this.shutdownRequested && this.stats.activeJobs === 0 && this.jobs.length === 0) {
@@ -149,7 +149,7 @@ var JobExecutor = /** @class */ (function () {
149
149
  secondsUntilMax = Math.max(1, maxJobSeconds - jobRunTime);
150
150
  // const secondsUntilKill = Math.max(1, this.opt.killAfter - jobRunTime)
151
151
  job.visibilityTimeout = Math.min(doubled, secondsUntilMax); //, secondsUntilKill)
152
- job.extendAtSecond = Math.round(jobRunTime + job.visibilityTimeout); // this is what we use next time
152
+ job.extendAtSecond = Math.round(jobRunTime + job.visibilityTimeout / 2); // this is what we use next time
153
153
  debug({ doubled: doubled, secondsUntilMax: secondsUntilMax, job: job });
154
154
  }
155
155
  }
@@ -159,7 +159,7 @@ var JobExecutor = /** @class */ (function () {
159
159
  for (_c in _a)
160
160
  _b.push(_c);
161
161
  _i = 0;
162
- _h.label = 1;
162
+ _m.label = 1;
163
163
  case 1:
164
164
  if (!(_i < _b.length)) return [3 /*break*/, 5];
165
165
  _c = _b[_i];
@@ -167,7 +167,7 @@ var JobExecutor = /** @class */ (function () {
167
167
  qrl = _c;
168
168
  jobsToExtend = jobsToExtendByQrl[qrl];
169
169
  debug({ qrl: qrl, jobsToExtend: jobsToExtend });
170
- _h.label = 2;
170
+ _m.label = 2;
171
171
  case 2:
172
172
  if (!jobsToExtend.length) return [3 /*break*/, 4];
173
173
  entries = [];
@@ -175,7 +175,7 @@ var JobExecutor = /** @class */ (function () {
175
175
  while (messageId++ < 10 && jobsToExtend.length) {
176
176
  job = jobsToExtend.shift();
177
177
  entry = {
178
- Id: '' + messageId,
178
+ Id: job.message.MessageId,
179
179
  ReceiptHandle: job.message.ReceiptHandle,
180
180
  VisibilityTimeout: job.visibilityTimeout
181
181
  };
@@ -186,9 +186,16 @@ var JobExecutor = /** @class */ (function () {
186
186
  debug({ ChangeMessageVisibilityBatch: input });
187
187
  return [4 /*yield*/, (0, sqs_js_1.getSQSClient)().send(new client_sqs_1.ChangeMessageVisibilityBatchCommand(input))];
188
188
  case 3:
189
- result = _h.sent();
189
+ result = _m.sent();
190
190
  debug('ChangeMessageVisibilityBatch returned', result);
191
191
  this.stats.sqsCalls++;
192
+ if (result.Failed) {
193
+ console.error('FAILED_MESSAGES', result.Failed);
194
+ for (_d = 0, _e = result.Failed; _d < _e.length; _d++) {
195
+ failed = _e[_d];
196
+ console.error('FAILED_TO_EXTEND_JOB', this.jobsByMessageId[failed.Id]);
197
+ }
198
+ }
192
199
  if (result.Successful) {
193
200
  count = result.Successful.length || 0;
194
201
  this.stats.timeoutsExtended += count;
@@ -204,19 +211,19 @@ var JobExecutor = /** @class */ (function () {
204
211
  _i++;
205
212
  return [3 /*break*/, 1];
206
213
  case 5:
207
- _d = jobsToDeleteByQrl;
208
- _e = [];
209
- for (_f in _d)
210
- _e.push(_f);
211
- _g = 0;
212
- _h.label = 6;
214
+ _f = jobsToDeleteByQrl;
215
+ _g = [];
216
+ for (_h in _f)
217
+ _g.push(_h);
218
+ _j = 0;
219
+ _m.label = 6;
213
220
  case 6:
214
- if (!(_g < _e.length)) return [3 /*break*/, 10];
215
- _f = _e[_g];
216
- if (!(_f in _d)) return [3 /*break*/, 9];
217
- qrl = _f;
221
+ if (!(_j < _g.length)) return [3 /*break*/, 10];
222
+ _h = _g[_j];
223
+ if (!(_h in _f)) return [3 /*break*/, 9];
224
+ qrl = _h;
218
225
  jobsToDelete = jobsToDeleteByQrl[qrl];
219
- _h.label = 7;
226
+ _m.label = 7;
220
227
  case 7:
221
228
  if (!jobsToDelete.length) return [3 /*break*/, 9];
222
229
  entries = [];
@@ -224,7 +231,7 @@ var JobExecutor = /** @class */ (function () {
224
231
  while (messageId++ < 10 && jobsToDelete.length) {
225
232
  job = jobsToDelete.shift();
226
233
  entry = {
227
- Id: '' + messageId,
234
+ Id: job.message.MessageId,
228
235
  ReceiptHandle: job.message.ReceiptHandle,
229
236
  VisibilityTimeout: job.visibilityTimeout
230
237
  };
@@ -235,8 +242,15 @@ var JobExecutor = /** @class */ (function () {
235
242
  debug({ DeleteMessageBatch: input });
236
243
  return [4 /*yield*/, (0, sqs_js_1.getSQSClient)().send(new client_sqs_1.DeleteMessageBatchCommand(input))];
237
244
  case 8:
238
- result = _h.sent();
245
+ result = _m.sent();
239
246
  this.stats.sqsCalls++;
247
+ if (result.Failed) {
248
+ console.error('FAILED_MESSAGES', result.Failed);
249
+ for (_k = 0, _l = result.Failed; _k < _l.length; _k++) {
250
+ failed = _l[_k];
251
+ console.error('FAILED_TO_DELETE_JOB', this.jobsByMessageId[failed.Id]);
252
+ }
253
+ }
240
254
  if (result.Successful) {
241
255
  count = result.Successful.length || 0;
242
256
  this.stats.jobsDeleted += count;
@@ -250,7 +264,7 @@ var JobExecutor = /** @class */ (function () {
250
264
  debug('DeleteMessageBatch returned', result);
251
265
  return [3 /*break*/, 7];
252
266
  case 9:
253
- _g++;
267
+ _j++;
254
268
  return [3 /*break*/, 6];
255
269
  case 10:
256
270
  // Get rid of deleted and failed jobs
@@ -95,8 +95,11 @@ var QueueManager = /** @class */ (function () {
95
95
  var secondsElapsed = Math.round((now - lastCheck) / 1000);
96
96
  debug({ icehouseCheck: { qrl: qrl, lastCheck: lastCheck, secondsToWait: secondsToWait, secondsElapsed: secondsElapsed } });
97
97
  var letOut = secondsElapsed > secondsToWait;
98
- if (letOut && this.opt.verbose) {
99
- console.error(chalk_1.default.blue('Coming out of icehouse:'), qrl);
98
+ if (letOut) {
99
+ delete this.icehouse[qrl];
100
+ if (this.opt.verbose) {
101
+ console.error(chalk_1.default.blue('Coming out of icehouse:'), qrl);
102
+ }
100
103
  }
101
104
  return !letOut;
102
105
  }
@@ -125,7 +128,10 @@ var QueueManager = /** @class */ (function () {
125
128
  case 1:
126
129
  pairs = _a.sent();
127
130
  if (this.opt.verbose)
128
- console.error(chalk_1.default.blue('Resolving queues:'));
131
+ console.error(chalk_1.default.blue('Resolving queues:'), pairs.map(function (_a) {
132
+ var qname = _a.qname;
133
+ return qname;
134
+ }));
129
135
  if (this.shutdownRequested)
130
136
  return [2 /*return*/];
131
137
  now = new Date();
@@ -142,6 +148,13 @@ var QueueManager = /** @class */ (function () {
142
148
  var qname = _a.qname, qrl = _a.qrl;
143
149
  var isFifo = qname.endsWith('.fifo');
144
150
  return _this.opt.fifo ? isFifo : true;
151
+ })
152
+ // next dead
153
+ .filter(function (_a) {
154
+ var qname = _a.qname, qrl = _a.qrl;
155
+ var isFifo = qname.endsWith('.fifo');
156
+ var isDead = isFifo ? qname.endsWith('_dead.fifo') : qname.endsWith('_dead');
157
+ return !isDead;
145
158
  })
146
159
  // then icehouse
147
160
  .filter(function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.27-alpha",
3
+ "version": "2.0.29-alpha",
4
4
  "description": "Language agnostic job queue for SQS",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/consumer.js CHANGED
@@ -97,7 +97,7 @@ export async function processMessages (queues, callback, options) {
97
97
  if (!shutdownRequested) {
98
98
  if (messages.length) {
99
99
  for (const message of messages) {
100
- jobExecutor.executeJob(message, callback, qname, qrl, () => queueManager.updateIcehouse(qrl, true))
100
+ jobExecutor.executeJob(message, callback, qname, qrl)
101
101
  }
102
102
  queueManager.updateIcehouse(qrl, false)
103
103
  } else {
@@ -146,7 +146,7 @@ export async function processMessages (queues, callback, options) {
146
146
  let jobsLeft = targetJobs
147
147
 
148
148
  if (opt.verbose) {
149
- console.error({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, freememThreshold, remainingMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, oneMinuteLoad, loadPerCore, loadFactor, overallFactor, targetJobs, activeQrls })
149
+ console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, jobCount: jobExecutor.activeJobCount(), allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls })
150
150
  }
151
151
  for (const { qname, qrl } of queueManager.getPairs()) {
152
152
  // debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
@@ -101,7 +101,7 @@ export class JobExecutor {
101
101
  const secondsUntilMax = Math.max(1, maxJobSeconds - jobRunTime)
102
102
  // const secondsUntilKill = Math.max(1, this.opt.killAfter - jobRunTime)
103
103
  job.visibilityTimeout = Math.min(doubled, secondsUntilMax) //, secondsUntilKill)
104
- job.extendAtSecond = Math.round(jobRunTime + job.visibilityTimeout) // this is what we use next time
104
+ job.extendAtSecond = Math.round(jobRunTime + job.visibilityTimeout / 2) // this is what we use next time
105
105
  debug({ doubled, secondsUntilMax, job })
106
106
  }
107
107
  }
@@ -119,7 +119,7 @@ export class JobExecutor {
119
119
  while (messageId++ < 10 && jobsToExtend.length) {
120
120
  const job = jobsToExtend.shift()
121
121
  const entry = {
122
- Id: '' + messageId,
122
+ Id: job.message.MessageId,
123
123
  ReceiptHandle: job.message.ReceiptHandle,
124
124
  VisibilityTimeout: job.visibilityTimeout
125
125
  }
@@ -133,6 +133,12 @@ export class JobExecutor {
133
133
  const result = await getSQSClient().send(new ChangeMessageVisibilityBatchCommand(input))
134
134
  debug('ChangeMessageVisibilityBatch returned', result)
135
135
  this.stats.sqsCalls++
136
+ if (result.Failed) {
137
+ console.error('FAILED_MESSAGES', result.Failed)
138
+ for (const failed of result.Failed) {
139
+ console.error('FAILED_TO_EXTEND_JOB', this.jobsByMessageId[failed.Id])
140
+ }
141
+ }
136
142
  if (result.Successful) {
137
143
  const count = result.Successful.length || 0
138
144
  this.stats.timeoutsExtended += count
@@ -156,7 +162,7 @@ export class JobExecutor {
156
162
  while (messageId++ < 10 && jobsToDelete.length) {
157
163
  const job = jobsToDelete.shift()
158
164
  const entry = {
159
- Id: '' + messageId,
165
+ Id: job.message.MessageId,
160
166
  ReceiptHandle: job.message.ReceiptHandle,
161
167
  VisibilityTimeout: job.visibilityTimeout
162
168
  }
@@ -169,6 +175,12 @@ export class JobExecutor {
169
175
  debug({ DeleteMessageBatch: input })
170
176
  const result = await getSQSClient().send(new DeleteMessageBatchCommand(input))
171
177
  this.stats.sqsCalls++
178
+ if (result.Failed) {
179
+ console.error('FAILED_MESSAGES', result.Failed)
180
+ for (const failed of result.Failed) {
181
+ console.error('FAILED_TO_DELETE_JOB', this.jobsByMessageId[failed.Id])
182
+ }
183
+ }
172
184
  if (result.Successful) {
173
185
  const count = result.Successful.length || 0
174
186
  this.stats.jobsDeleted += count
@@ -57,8 +57,11 @@ export class QueueManager {
57
57
  const secondsElapsed = Math.round((now - lastCheck) / 1000)
58
58
  debug({ icehouseCheck: { qrl, lastCheck, secondsToWait, secondsElapsed } })
59
59
  const letOut = secondsElapsed > secondsToWait
60
- if (letOut && this.opt.verbose) {
61
- console.error(chalk.blue('Coming out of icehouse:'), qrl)
60
+ if (letOut) {
61
+ delete this.icehouse[qrl]
62
+ if (this.opt.verbose) {
63
+ console.error(chalk.blue('Coming out of icehouse:'), qrl)
64
+ }
62
65
  }
63
66
  return !letOut
64
67
  } else {
@@ -79,7 +82,7 @@ export class QueueManager {
79
82
  // Start processing
80
83
  const qnames = this.queues.map(queue => normalizeQueueName(queue, this.opt))
81
84
  const pairs = await getQnameUrlPairs(qnames, this.opt)
82
- if (this.opt.verbose) console.error(chalk.blue('Resolving queues:'))
85
+ if (this.opt.verbose) console.error(chalk.blue('Resolving queues:'), pairs.map(({ qname }) => qname))
83
86
 
84
87
  if (this.shutdownRequested) return
85
88
 
@@ -97,6 +100,12 @@ export class QueueManager {
97
100
  const isFifo = qname.endsWith('.fifo')
98
101
  return this.opt.fifo ? isFifo : true
99
102
  })
103
+ // next dead
104
+ .filter(({ qname, qrl }) => {
105
+ const isFifo = qname.endsWith('.fifo')
106
+ const isDead = isFifo ? qname.endsWith('_dead.fifo') : qname.endsWith('_dead')
107
+ return !isDead
108
+ })
100
109
  // then icehouse
101
110
  .filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now))
102
111