qdone 2.0.32-alpha → 2.0.34-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.
@@ -61,7 +61,7 @@ async function processMessages(queues, callback, options) {
61
61
  lastLatency = latency;
62
62
  });
63
63
  const jobExecutor = new jobExecutor_js_1.JobExecutor(opt);
64
- const queueManager = new queueManager_js_1.QueueManager(opt, queues, 60);
64
+ const queueManager = new queueManager_js_1.QueueManager(opt, queues, 10);
65
65
  const cores = (0, os_1.cpus)().length;
66
66
  // debug({ systemMonitor, jobExecutor, queueManager })
67
67
  // This delay function keeps a timeout reference around so it can be
@@ -101,8 +101,7 @@ async function processMessages(queues, callback, options) {
101
101
  }
102
102
  }
103
103
  // Max job accounting
104
- if (messages.length)
105
- maxReturnCount -= messages.length;
104
+ maxReturnCount -= maxMessages;
106
105
  activeQrls.delete(qrl);
107
106
  }
108
107
  catch (e) {
@@ -117,7 +116,8 @@ async function processMessages(queues, callback, options) {
117
116
  };
118
117
  while (!shutdownRequested) { // eslint-disable-line
119
118
  // Figure out how we are running
120
- const allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.runningJobCount() - maxReturnCount);
119
+ const runningJobs = jobExecutor.runningJobCount();
120
+ const allowedJobs = Math.max(0, opt.maxConcurrentJobs - maxReturnCount - runningJobs);
121
121
  // Latency
122
122
  const maxLatency = 100;
123
123
  const latency = systemMonitor.getLatency() || 10;
@@ -137,12 +137,14 @@ async function processMessages(queues, callback, options) {
137
137
  const targetJobs = Math.round(allowedJobs * overallFactor);
138
138
  let jobsLeft = targetJobs;
139
139
  if (opt.verbose) {
140
- // console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, jobCount: jobExecutor.activeJobCount(), allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls })
140
+ console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls });
141
141
  }
142
142
  for (const { qname, qrl } of queueManager.getPairs()) {
143
143
  // const qcount = jobExecutor.runningJobCountForQueue(qname)
144
144
  // console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
145
- if (jobsLeft <= 0 || activeQrls.has(qrl))
145
+ if (jobsLeft <= 0)
146
+ break;
147
+ if (activeQrls.has(qrl))
146
148
  continue;
147
149
  const maxMessages = Math.min(10, jobsLeft);
148
150
  listen(qname, qrl, maxMessages);
@@ -40,10 +40,8 @@ class JobExecutor {
40
40
  if (this.opt.verbose) {
41
41
  console.error(chalk_1.default.blue('Shutting down jobExecutor'));
42
42
  }
43
- while (this.stats.activeJobs > 0) {
44
- await this.maintainPromise;
45
- await this.maintainVisibility();
46
- }
43
+ await this.maintainPromise;
44
+ await this.maintainVisibility();
47
45
  }
48
46
  activeJobCount() {
49
47
  return this.stats.activeJobs;
@@ -122,19 +120,18 @@ class JobExecutor {
122
120
  console.error(chalk_1.default.blue('Jobs: '));
123
121
  for (const [qname, jobs] of this.jobsByQueue.entries()) {
124
122
  if (jobs.size) {
125
- console.error(chalk_1.default.blue(' queue:'), qname);
126
- for (const job of jobs)
127
- if (job.status === 'running')
128
- console.error(chalk_1.default.green(' running: '), job.payload);
123
+ const stats = {};
129
124
  for (const job of jobs)
130
- if (job.status === 'waiting')
131
- console.error(chalk_1.default.gold(' waiting:'), job.payload);
132
- for (const job of jobs)
133
- if (job.status === 'complete' || job.status === 'deleting')
134
- console.error(chalk_1.default.blue(' complete:'), job.payload);
135
- for (const job of jobs)
136
- if (job.status === 'failed')
137
- console.error(chalk_1.default.red(' failed:'), job.payload);
125
+ stats[job.status] = (stats[job.status] || 0) + 1;
126
+ console.error(chalk_1.default.blue(' queue:'), qname);
127
+ if (stats.running)
128
+ console.error(chalk_1.default.green(' running: '), stats.running);
129
+ if (stats.waiting)
130
+ console.error(chalk_1.default.yellow(' waiting: '), stats.waiting);
131
+ if (stats.deleting)
132
+ console.error(chalk_1.default.blue(' complete: '), stats.deleting);
133
+ if (stats.failed)
134
+ console.error(chalk_1.default.red(' failed: '), stats.failed);
138
135
  }
139
136
  }
140
137
  }
@@ -146,6 +146,7 @@ class QueueManager {
146
146
  }
147
147
  getPairs() {
148
148
  const now = new Date();
149
+ this.selectedPairs.sort(() => 0.5 - Math.random());
149
150
  return this.selectedPairs.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now));
150
151
  }
151
152
  async shutdown() {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.32-alpha",
3
+ "version": "2.0.34-alpha",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "qdone",
9
- "version": "2.0.32-alpha",
9
+ "version": "2.0.34-alpha",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cloudwatch": "3.465.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.32-alpha",
3
+ "version": "2.0.34-alpha",
4
4
  "description": "Language agnostic job queue for SQS",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/consumer.js CHANGED
@@ -61,7 +61,7 @@ export async function processMessages (queues, callback, options) {
61
61
  lastLatency = latency
62
62
  })
63
63
  const jobExecutor = new JobExecutor(opt)
64
- const queueManager = new QueueManager(opt, queues, 60)
64
+ const queueManager = new QueueManager(opt, queues, 10)
65
65
  const cores = cpus().length
66
66
  // debug({ systemMonitor, jobExecutor, queueManager })
67
67
 
@@ -105,7 +105,7 @@ export async function processMessages (queues, callback, options) {
105
105
  }
106
106
 
107
107
  // Max job accounting
108
- if (messages.length) maxReturnCount -= messages.length
108
+ maxReturnCount -= maxMessages
109
109
  activeQrls.delete(qrl)
110
110
  } catch (e) {
111
111
  // If the queue has been cleaned up, we should back off anyway
@@ -119,7 +119,8 @@ export async function processMessages (queues, callback, options) {
119
119
 
120
120
  while (!shutdownRequested) { // eslint-disable-line
121
121
  // Figure out how we are running
122
- const allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.runningJobCount() - maxReturnCount)
122
+ const runningJobs = jobExecutor.runningJobCount()
123
+ const allowedJobs = Math.max(0, opt.maxConcurrentJobs - maxReturnCount - runningJobs)
123
124
 
124
125
  // Latency
125
126
  const maxLatency = 100
@@ -144,12 +145,13 @@ export async function processMessages (queues, callback, options) {
144
145
  let jobsLeft = targetJobs
145
146
 
146
147
  if (opt.verbose) {
147
- // console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, jobCount: jobExecutor.activeJobCount(), allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls })
148
+ console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls })
148
149
  }
149
150
  for (const { qname, qrl } of queueManager.getPairs()) {
150
151
  // const qcount = jobExecutor.runningJobCountForQueue(qname)
151
152
  // console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
152
- if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
153
+ if (jobsLeft <= 0) break
154
+ if (activeQrls.has(qrl)) continue
153
155
  const maxMessages = Math.min(10, jobsLeft)
154
156
  listen(qname, qrl, maxMessages)
155
157
  jobsLeft -= maxMessages
@@ -41,10 +41,8 @@ export class JobExecutor {
41
41
  if (this.opt.verbose) {
42
42
  console.error(chalk.blue('Shutting down jobExecutor'))
43
43
  }
44
- while (this.stats.activeJobs > 0) {
45
- await this.maintainPromise
46
- await this.maintainVisibility()
47
- }
44
+ await this.maintainPromise
45
+ await this.maintainVisibility()
48
46
  }
49
47
 
50
48
  activeJobCount () {
@@ -129,11 +127,13 @@ export class JobExecutor {
129
127
  console.error(chalk.blue('Jobs: '))
130
128
  for (const [qname, jobs] of this.jobsByQueue.entries()) {
131
129
  if (jobs.size) {
130
+ const stats = {}
131
+ for (const job of jobs) stats[job.status] = (stats[job.status] || 0) + 1
132
132
  console.error(chalk.blue(' queue:'), qname)
133
- for (const job of jobs) if (job.status === 'running') console.error(chalk.green(' running: '), job.payload)
134
- for (const job of jobs) if (job.status === 'waiting') console.error(chalk.gold(' waiting:'), job.payload)
135
- for (const job of jobs) if (job.status === 'complete' || job.status === 'deleting') console.error(chalk.blue(' complete:'), job.payload)
136
- for (const job of jobs) if (job.status === 'failed') console.error(chalk.red(' failed:'), job.payload)
133
+ if (stats.running) console.error(chalk.green(' running: '), stats.running)
134
+ if (stats.waiting) console.error(chalk.yellow(' waiting: '), stats.waiting)
135
+ if (stats.deleting) console.error(chalk.blue(' complete: '), stats.deleting)
136
+ if (stats.failed) console.error(chalk.red(' failed: '), stats.failed)
137
137
  }
138
138
  }
139
139
  }
@@ -149,6 +149,7 @@ export class QueueManager {
149
149
 
150
150
  getPairs () {
151
151
  const now = new Date()
152
+ this.selectedPairs.sort(() => 0.5 - Math.random())
152
153
  return this.selectedPairs.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now))
153
154
  }
154
155