@joystick.js/node-canary 0.0.0-canary.292 → 0.0.0-canary.293
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/dist/app/queues/index.js +22 -22
- package/package.json +1 -1
package/dist/app/queues/index.js
CHANGED
|
@@ -97,45 +97,42 @@ class Queue {
|
|
|
97
97
|
setInterval(async () => {
|
|
98
98
|
const okayToRunJobs = await this._checkIfOkayToRunJobs();
|
|
99
99
|
if (okayToRunJobs && !process.env.HALT_QUEUES) {
|
|
100
|
-
const
|
|
101
|
-
this.handleNextJob(
|
|
100
|
+
const nextJob2 = await this.db.getNextJobToRun();
|
|
101
|
+
this.handleNextJob(nextJob2);
|
|
102
102
|
}
|
|
103
103
|
}, 300);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
async handleNextJob(
|
|
107
|
-
const job_definition = this.options.jobs[
|
|
108
|
-
if (
|
|
106
|
+
async handleNextJob(nextJob2 = {}) {
|
|
107
|
+
const job_definition = this.options.jobs[nextJob2?.job];
|
|
108
|
+
if (nextJob2 && nextJob2?.job && job_definition && typeof job_definition?.run === "function") {
|
|
109
109
|
try {
|
|
110
110
|
if (typeof job_definition?.preflight?.okayToRun === "function") {
|
|
111
|
-
const okay_to_run = await job_definition?.preflight?.okayToRun(
|
|
111
|
+
const okay_to_run = await job_definition?.preflight?.okayToRun(nextJob2?.payload, nextJob2);
|
|
112
112
|
if (!okay_to_run) {
|
|
113
|
-
return this._handleRequeueJob(
|
|
113
|
+
return this._handleRequeueJob(nextJob2, timestamps.get_future_time("seconds", job_definition?.preflight?.requeueDelayInSeconds || 10));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
if (!isNaN(job_definition?.maxAttempts)) {
|
|
117
117
|
console.log({
|
|
118
|
-
...
|
|
118
|
+
...nextJob2,
|
|
119
119
|
maxAttempts: job_definition?.maxAttempts
|
|
120
120
|
});
|
|
121
|
-
if (
|
|
122
|
-
return this._handleDeleteJob(
|
|
121
|
+
if (nextJob2?.attempts >= parseInt(job_definition?.maxAttempts, 10)) {
|
|
122
|
+
return this._handleDeleteJob(nextJob2?._id);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
await this._logAttempt(
|
|
126
|
-
await job_definition.run(
|
|
127
|
-
...
|
|
125
|
+
await this._logAttempt(nextJob2?._id);
|
|
126
|
+
await job_definition.run(nextJob2?.payload, {
|
|
127
|
+
...nextJob2,
|
|
128
128
|
queue: this,
|
|
129
|
-
completed: () => this._handleJobCompleted(
|
|
130
|
-
failed: (error) => this._handleJobFailed(
|
|
131
|
-
delete: () => this._handleDeleteJob(
|
|
132
|
-
requeue: (nextRunAt = "") => this._handleRequeueJob(
|
|
129
|
+
completed: () => this._handleJobCompleted(nextJob2?._id),
|
|
130
|
+
failed: (error) => this._handleJobFailed(nextJob2?._id, job_definition, error),
|
|
131
|
+
delete: () => this._handleDeleteJob(nextJob2?._id),
|
|
132
|
+
requeue: (nextRunAt = "") => this._handleRequeueJob(nextJob2, nextRunAt)
|
|
133
133
|
});
|
|
134
134
|
} catch (exception) {
|
|
135
|
-
this._handleJobFailed(
|
|
136
|
-
if (job_definition?.requeueOnFailure) {
|
|
137
|
-
this._handleRequeueJob(nextJob?.nextRunAt, dayjs().add(10, "seconds").format());
|
|
138
|
-
}
|
|
135
|
+
this._handleJobFailed(nextJob2?._id, job_definition, exception);
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
138
|
}
|
|
@@ -145,7 +142,10 @@ class Queue {
|
|
|
145
142
|
_handleJobCompleted(jobId = "") {
|
|
146
143
|
return this.db.setJobCompleted(jobId);
|
|
147
144
|
}
|
|
148
|
-
_handleJobFailed(jobId = "", error = "") {
|
|
145
|
+
_handleJobFailed(jobId = "", job_definition = {}, error = "") {
|
|
146
|
+
if (job_definition?.requeueOnFailure) {
|
|
147
|
+
return this._handleRequeueJob(nextJob?.nextRunAt, timestamps.get_future_time("seconds", 10));
|
|
148
|
+
}
|
|
149
149
|
return this.db.setJobFailed(jobId, error);
|
|
150
150
|
}
|
|
151
151
|
_handleDeleteJob(jobId = "") {
|