@joystick.js/node-canary 0.0.0-canary.325 → 0.0.0-canary.327
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 +12 -4
- package/package.json +1 -1
package/dist/app/queues/index.js
CHANGED
|
@@ -31,7 +31,7 @@ class Queue {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
return boundQueries;
|
|
34
|
-
}, {});
|
|
34
|
+
}, { _connection: db });
|
|
35
35
|
if (!is_external) {
|
|
36
36
|
await this.db.initializeDatabase(queuesDatabase);
|
|
37
37
|
if (this?.options?.runOnStartup) {
|
|
@@ -51,15 +51,23 @@ class Queue {
|
|
|
51
51
|
}
|
|
52
52
|
return process.databases._queues;
|
|
53
53
|
}
|
|
54
|
-
add(options = {}) {
|
|
54
|
+
async add(options = {}) {
|
|
55
55
|
const nextRunAt = options?.nextRunAt === "now" || !options?.nextRunAt ? new Date().toISOString() : options?.nextRunAt;
|
|
56
|
-
|
|
56
|
+
const job_to_add = {
|
|
57
57
|
_id: generateId(),
|
|
58
58
|
status: "pending",
|
|
59
59
|
environment: process.env.NODE_ENV,
|
|
60
60
|
...options,
|
|
61
61
|
nextRunAt
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
|
+
const job_definition = this.options.jobs[options?.job];
|
|
64
|
+
if (job_definition && typeof job_definition?.preflight?.onBeforeAdd === "function") {
|
|
65
|
+
const canAddJob = await job_definition?.preflight?.onBeforeAdd(job_to_add, this.db._connection, this.name);
|
|
66
|
+
if (!canAddJob) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.db.addJob(job_to_add);
|
|
63
71
|
}
|
|
64
72
|
async _checkIfOkayToRunJobs() {
|
|
65
73
|
const jobsRunning = await this._getNumberOfJobsRunning();
|