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) {
@@ -70,4 +70,5 @@ export interface JobUpdates {
70
70
  retry?: RetryOptions;
71
71
  repeat?: RepeatOptions;
72
72
  status?: JobStatus;
73
+ attempts?: number;
73
74
  }
@@ -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,
@@ -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) {
@@ -142,6 +142,7 @@ class Worker {
142
142
  });
143
143
  }
144
144
  else {
145
+ await this.store.update(job._id, { attempts });
145
146
  await this.store.markFailed(job._id, error.message);
146
147
  this.emitter.emitSafe("job:fail", { job, error });
147
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongo-job-scheduler",
3
- "version": "0.1.12",
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",