jm2 0.1.10 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jm2",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Job Manager 2 - A simple yet powerful job scheduler combining cron and at functionality",
5
5
  "type": "module",
6
6
  "main": "src/cli/index.js",
@@ -178,8 +178,6 @@ class DarwinService extends PlatformService {
178
178
  </array>
179
179
  <key>RunAtLoad</key>
180
180
  <true/>
181
- <key>KeepAlive</key>
182
- <true/>
183
181
  <key>StandardOutPath</key>
184
182
  <string>${stdoutPath}</string>
185
183
  <key>StandardErrorPath</key>
@@ -344,8 +342,6 @@ Type=forking
344
342
  ExecStart=${nodePath} ${jm2Path} start
345
343
  ExecStop=${nodePath} ${jm2Path} stop
346
344
  ExecReload=${nodePath} ${jm2Path} restart
347
- Restart=always
348
- RestartSec=10
349
345
  Environment="JM2_DATA_DIR=${dataDir}"
350
346
  StandardOutput=append:${join(logDir, 'service-out.log')}
351
347
  StandardError=append:${join(logDir, 'service-err.log')}
@@ -196,6 +196,7 @@ export class Scheduler {
196
196
  /**
197
197
  * Recalculate next run times for periodic jobs that have drifted into the past
198
198
  * This handles system sleep/wake scenarios where nextRun becomes stale
199
+ * Only recalculates jobs that are significantly overdue (missed multiple runs)
199
200
  * @param {Date} now - Current time
200
201
  */
201
202
  recalculateStalePeriodicJobs(now) {
@@ -204,17 +205,21 @@ export class Scheduler {
204
205
  job.status === JobStatus.ACTIVE &&
205
206
  job.type === JobType.CRON &&
206
207
  job.cron &&
207
- job.nextRun &&
208
- job.nextRun < now
208
+ job.nextRun
209
209
  ) {
210
- // Job's next run is in the past - recalculate from now to find next future occurrence
211
- const newNextRun = this.calculateNextRun(job, now);
212
- if (newNextRun && newNextRun !== job.nextRun) {
213
- this.logger.debug(
214
- `Recalculating next run for job ${id} (${job.name || 'unnamed'}): ` +
215
- `${job.nextRun.toISOString()} ${newNextRun.toISOString()}`
216
- );
217
- this.updateJobNextRun(id, newNextRun);
210
+ const timeSinceNextRun = now.getTime() - job.nextRun.getTime();
211
+ const isSignificantlyOverdue = timeSinceNextRun > this.checkIntervalMs * 2;
212
+
213
+ if (isSignificantlyOverdue) {
214
+ // Job is significantly overdue - recalculate from now to find next future occurrence
215
+ const newNextRun = this.calculateNextRun(job, now);
216
+ if (newNextRun && newNextRun !== job.nextRun) {
217
+ this.logger.debug(
218
+ `Recalculating next run for job ${id} (${job.name || 'unnamed'}): ` +
219
+ `${job.nextRun.toISOString()} → ${newNextRun.toISOString()}`
220
+ );
221
+ this.updateJobNextRun(id, newNextRun);
222
+ }
218
223
  }
219
224
  }
220
225
  }