@joystick.js/node-canary 0.0.0-canary.293 → 0.0.0-canary.294

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.
@@ -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 nextJob2 = await this.db.getNextJobToRun();
101
- this.handleNextJob(nextJob2);
100
+ const nextJob = await this.db.getNextJobToRun();
101
+ this.handleNextJob(nextJob);
102
102
  }
103
103
  }, 300);
104
104
  });
105
105
  }
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") {
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(nextJob2?.payload, nextJob2);
111
+ const okay_to_run = await job_definition?.preflight?.okayToRun(nextJob?.payload, nextJob);
112
112
  if (!okay_to_run) {
113
- return this._handleRequeueJob(nextJob2, timestamps.get_future_time("seconds", job_definition?.preflight?.requeueDelayInSeconds || 10));
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
- ...nextJob2,
118
+ ...nextJob,
119
119
  maxAttempts: job_definition?.maxAttempts
120
120
  });
121
- if (nextJob2?.attempts >= parseInt(job_definition?.maxAttempts, 10)) {
122
- return this._handleDeleteJob(nextJob2?._id);
121
+ if (nextJob?.attempts >= parseInt(job_definition?.maxAttempts, 10)) {
122
+ return this._handleDeleteJob(nextJob?._id);
123
123
  }
124
124
  }
125
- await this._logAttempt(nextJob2?._id);
126
- await job_definition.run(nextJob2?.payload, {
127
- ...nextJob2,
125
+ await this._logAttempt(nextJob?._id);
126
+ await job_definition.run(nextJob?.payload, {
127
+ ...nextJob,
128
128
  queue: this,
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)
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(nextJob2?._id, job_definition, exception);
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(jobId = "", job_definition = {}, error = "") {
145
+ _handleJobFailed(nextJob = {}, job_definition = {}, error = "") {
146
146
  if (job_definition?.requeueOnFailure) {
147
- return this._handleRequeueJob(nextJob?.nextRunAt, timestamps.get_future_time("seconds", 10));
147
+ return this._handleRequeueJob(nextJob?._id, timestamps.get_future_time("seconds", 10));
148
148
  }
149
- return this.db.setJobFailed(jobId, error);
149
+ return this.db.setJobFailed(nextJob?._id, error);
150
150
  }
151
151
  _handleDeleteJob(jobId = "") {
152
152
  return this.db.deleteJob(jobId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.293",
3
+ "version": "0.0.0-canary.294",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",