@joystick.js/node-canary 0.0.0-canary.293 → 0.0.0-canary.295
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 +21 -21
- package/package.json +1 -1
package/dist/app/queues/index.js
CHANGED
|
@@ -97,42 +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 nextJob = await this.db.getNextJobToRun();
|
|
101
|
+
this.handleNextJob(nextJob);
|
|
102
102
|
}
|
|
103
103
|
}, 300);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
async handleNextJob(
|
|
107
|
-
const job_definition = this.options.jobs[
|
|
108
|
-
if (
|
|
106
|
+
async handleNextJob(nextJob = {}) {
|
|
107
|
+
const job_definition = this.options.jobs[nextJob?.job];
|
|
108
|
+
if (nextJob && nextJob?.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(nextJob?.payload, nextJob);
|
|
112
112
|
if (!okay_to_run) {
|
|
113
|
-
return this._handleRequeueJob(
|
|
113
|
+
return this._handleRequeueJob(nextJob, 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
|
+
...nextJob,
|
|
119
119
|
maxAttempts: job_definition?.maxAttempts
|
|
120
120
|
});
|
|
121
|
-
if (
|
|
122
|
-
return this._handleDeleteJob(
|
|
121
|
+
if (nextJob?.attempts >= parseInt(job_definition?.maxAttempts, 10)) {
|
|
122
|
+
return this._handleDeleteJob(nextJob?._id);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
await this._logAttempt(
|
|
126
|
-
await job_definition.run(
|
|
127
|
-
...
|
|
125
|
+
await this._logAttempt(nextJob?._id);
|
|
126
|
+
await job_definition.run(nextJob?.payload, {
|
|
127
|
+
...nextJob,
|
|
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(nextJob?._id),
|
|
130
|
+
failed: (error) => this._handleJobFailed(nextJob, job_definition, error),
|
|
131
|
+
delete: () => this._handleDeleteJob(nextJob?._id),
|
|
132
|
+
requeue: (nextRunAt = "") => this._handleRequeueJob(nextJob, nextRunAt)
|
|
133
133
|
});
|
|
134
134
|
} catch (exception) {
|
|
135
|
-
this._handleJobFailed(
|
|
135
|
+
this._handleJobFailed(nextJob, job_definition, exception);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
@@ -142,11 +142,11 @@ class Queue {
|
|
|
142
142
|
_handleJobCompleted(jobId = "") {
|
|
143
143
|
return this.db.setJobCompleted(jobId);
|
|
144
144
|
}
|
|
145
|
-
_handleJobFailed(
|
|
145
|
+
_handleJobFailed(nextJob = {}, job_definition = {}, error = "") {
|
|
146
146
|
if (job_definition?.requeueOnFailure) {
|
|
147
|
-
return this._handleRequeueJob(nextJob?.
|
|
147
|
+
return this._handleRequeueJob(nextJob?._id, timestamps.get_future_time("seconds", 10));
|
|
148
148
|
}
|
|
149
|
-
return this.db.setJobFailed(
|
|
149
|
+
return this.db.setJobFailed(nextJob?._id, error);
|
|
150
150
|
}
|
|
151
151
|
_handleDeleteJob(jobId = "") {
|
|
152
152
|
return this.db.deleteJob(jobId);
|