mongo-job-scheduler 0.1.12 → 0.1.14
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.
|
@@ -150,6 +150,9 @@ class InMemoryJobStore {
|
|
|
150
150
|
if (updates.status !== undefined) {
|
|
151
151
|
job.status = updates.status;
|
|
152
152
|
}
|
|
153
|
+
if (updates.attempts !== undefined) {
|
|
154
|
+
job.attempts = updates.attempts;
|
|
155
|
+
}
|
|
153
156
|
job.updatedAt = new Date();
|
|
154
157
|
}
|
|
155
158
|
async findAll(query) {
|
|
@@ -37,6 +37,9 @@ class MongoJobStore {
|
|
|
37
37
|
createdAt: now,
|
|
38
38
|
updatedAt: now,
|
|
39
39
|
};
|
|
40
|
+
if (doc.dedupeKey === undefined || doc.dedupeKey === null) {
|
|
41
|
+
delete doc.dedupeKey;
|
|
42
|
+
}
|
|
40
43
|
if (job.dedupeKey) {
|
|
41
44
|
// Idempotent insert
|
|
42
45
|
const result = await this.collection.findOneAndUpdate({ dedupeKey: job.dedupeKey }, { $setOnInsert: doc }, { upsert: true, returnDocument: "after" });
|
|
@@ -50,13 +53,17 @@ class MongoJobStore {
|
|
|
50
53
|
const docs = jobs.map((job) => {
|
|
51
54
|
// IMPORTANT: strip _id completely
|
|
52
55
|
const { _id, ...jobWithoutId } = job;
|
|
53
|
-
|
|
56
|
+
const doc = {
|
|
54
57
|
...jobWithoutId,
|
|
55
58
|
status: job.status ?? "pending",
|
|
56
59
|
attempts: job.attempts ?? 0,
|
|
57
60
|
createdAt: now,
|
|
58
61
|
updatedAt: now,
|
|
59
62
|
};
|
|
63
|
+
if (doc.dedupeKey === undefined || doc.dedupeKey === null) {
|
|
64
|
+
delete doc.dedupeKey;
|
|
65
|
+
}
|
|
66
|
+
return doc;
|
|
60
67
|
});
|
|
61
68
|
if (docs.length === 0)
|
|
62
69
|
return [];
|
|
@@ -128,7 +135,7 @@ class MongoJobStore {
|
|
|
128
135
|
// RESCHEDULE
|
|
129
136
|
// --------------------------------------------------
|
|
130
137
|
async reschedule(id, nextRunAt, updates) {
|
|
131
|
-
await this.collection.updateOne({ _id: id }, {
|
|
138
|
+
const result = await this.collection.updateOne({ _id: id }, {
|
|
132
139
|
$set: {
|
|
133
140
|
status: "pending",
|
|
134
141
|
nextRunAt,
|
|
@@ -212,6 +219,8 @@ class MongoJobStore {
|
|
|
212
219
|
$set.repeat = updates.repeat;
|
|
213
220
|
if (updates.status !== undefined)
|
|
214
221
|
$set.status = updates.status;
|
|
222
|
+
if (updates.attempts !== undefined)
|
|
223
|
+
$set.attempts = updates.attempts;
|
|
215
224
|
await this.collection.updateOne({ _id: id }, { $set });
|
|
216
225
|
}
|
|
217
226
|
async findAll(query) {
|
package/dist/worker/worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongo-job-scheduler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Production-grade MongoDB-backed job scheduler with retries, cron, timezone support, and crash recovery",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Darshan Bhut",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"scheduler"
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "tsc",
|
|
43
|
+
"build": "tsc -p tsconfig.build.json",
|
|
44
44
|
"test": "jest",
|
|
45
45
|
"test:mongo": "jest tests/mongo",
|
|
46
46
|
"test:stress": "jest tests/stress",
|