@joystick.js/node-canary 0.0.0-canary.287 → 0.0.0-canary.288

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.
@@ -12,6 +12,10 @@ var queues_default = {
12
12
  const db = this.db?.collection(`queue_${this.queue.name}`);
13
13
  return db.deleteOne({ _id: jobId });
14
14
  },
15
+ deleteIncompleteJobsForMachine: function() {
16
+ const db = this.db?.collection(`queue_${this.queue.name}`);
17
+ return db.deleteMany({ status: { $in: ["incomplete", "running"] }, lockedBy: this.machineId });
18
+ },
15
19
  getJobs: function(query = {}) {
16
20
  const db = this.db?.collection(`queue_${this.queue.name}`);
17
21
  return db.find(query).toArray();
@@ -55,6 +59,14 @@ var queues_default = {
55
59
  db.createIndex({ failedAt: 1 }, { expireAfterSeconds: this?.queue?.options?.cleanup?.failedAfterSeconds });
56
60
  }
57
61
  },
62
+ logAttempt: function(jobId = "") {
63
+ const db = this.db?.collection(`queue_${this.queue.name}`);
64
+ return db.updateOne({ _id: jobId }, {
65
+ $inc: {
66
+ attempts: 1
67
+ }
68
+ });
69
+ },
58
70
  requeueJob: function(jobId = "", nextRunAt = null) {
59
71
  const db = this.db?.collection(`queue_${this.queue.name}`);
60
72
  return db.updateOne({ _id: jobId }, {
@@ -67,10 +79,6 @@ var queues_default = {
67
79
  }
68
80
  });
69
81
  },
70
- deleteIncompleteJobsForMachine: function() {
71
- const db = this.db?.collection(`queue_${this.queue.name}`);
72
- return db.deleteMany({ status: { $in: ["incomplete", "running"] }, lockedBy: this.machineId });
73
- },
74
82
  setJobCompleted: function(jobId = "") {
75
83
  const db = this.db?.collection(`queue_${this.queue.name}`);
76
84
  return db.updateOne({ _id: jobId }, {
@@ -46,6 +46,20 @@ var queues_default = {
46
46
  jobId
47
47
  ]);
48
48
  },
49
+ deleteIncompleteJobsForMachine: function() {
50
+ const db = this?.db;
51
+ return db?.query(`
52
+ DELETE FROM
53
+ queue_${this.queue.name}
54
+ WHERE
55
+ status = ANY($1)
56
+ AND
57
+ locked_by = $2
58
+ `, [
59
+ ["incomplete", "running"],
60
+ this.machineId
61
+ ]);
62
+ },
49
63
  getJobs: function(query = {}) {
50
64
  const db = this?.db;
51
65
  return db?.query(`
@@ -138,6 +152,19 @@ var queues_default = {
138
152
  });
139
153
  }
140
154
  },
155
+ logAttempt: function(jobId = "") {
156
+ const db = this?.db;
157
+ return db?.query(`
158
+ UPDATE
159
+ queue_${this.queue.name}
160
+ SET
161
+ attempts = attempts + 1
162
+ WHERE
163
+ _id = $1
164
+ `, [
165
+ jobId
166
+ ]);
167
+ },
141
168
  requeueJob: function(jobId = "", nextRunAt = null) {
142
169
  const db = this?.db;
143
170
  return db?.query(`
@@ -156,20 +183,6 @@ var queues_default = {
156
183
  jobId
157
184
  ]);
158
185
  },
159
- deleteIncompleteJobsForMachine: function() {
160
- const db = this?.db;
161
- return db?.query(`
162
- DELETE FROM
163
- queue_${this.queue.name}
164
- WHERE
165
- status = ANY($1)
166
- AND
167
- locked_by = $2
168
- `, [
169
- ["incomplete", "running"],
170
- this.machineId
171
- ]);
172
- },
173
186
  setJobCompleted: function(jobId = "") {
174
187
  const db = this?.db;
175
188
  return db?.query(`
@@ -105,6 +105,7 @@ class Queue {
105
105
  async handleNextJob(nextJob = {}) {
106
106
  if (nextJob && nextJob?.job && this.options.jobs[nextJob?.job] && typeof this.options.jobs[nextJob?.job]?.run === "function") {
107
107
  try {
108
+ await this._logAttempt(nextJob?._id);
108
109
  await this.options.jobs[nextJob.job].run(nextJob?.payload, {
109
110
  ...nextJob,
110
111
  queue: this,
@@ -121,6 +122,9 @@ class Queue {
121
122
  }
122
123
  }
123
124
  }
125
+ _logAttempt(jobId = "") {
126
+ return this.db.logAttempt(jobId);
127
+ }
124
128
  _handleJobCompleted(jobId = "") {
125
129
  return this.db.setJobCompleted(jobId);
126
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.287",
3
+ "version": "0.0.0-canary.288",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",