mongo-job-scheduler 0.1.13 → 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.
@@ -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
- return {
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongo-job-scheduler",
3
- "version": "0.1.13",
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",