@cronwatch/sdk 0.14.1 → 0.14.2

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/index.cjs CHANGED
@@ -722,7 +722,7 @@ function onCheck(def, stored, lastRun, state, now) {
722
722
  return { state: next, alerts, nextExpectedAt, dueAt: exp.dueAt };
723
723
  }
724
724
  function isStuck(def, run, now) {
725
- return run.status === "running" && now - run.startedAt > timeoutMs(def);
725
+ return run.status === "running" && run.finishedAt === null && now - run.startedAt > timeoutMs(def);
726
726
  }
727
727
  function muteOpens(previous, next) {
728
728
  const muted = cloneState(next);
@@ -1218,7 +1218,7 @@ function staticAsset(path, base) {
1218
1218
  }
1219
1219
 
1220
1220
  // src/version.ts
1221
- var VERSION = "0.14.1";
1221
+ var VERSION = "0.14.2";
1222
1222
  var API_VERSION = 1;
1223
1223
 
1224
1224
  // src/routes/timeline.ts
@@ -3148,17 +3148,16 @@ ${id}`;
3148
3148
  const definition = toStored(declared);
3149
3149
  const stored = await this.store.getRun(run.id);
3150
3150
  if (stored) return this.recordOver(definition, stored, run, evaluate);
3151
+ const inserted = evaluate ? { ...run, status: "running" } : run;
3151
3152
  try {
3152
- await this.store.insertRun(run);
3153
+ await this.store.insertRun(inserted);
3153
3154
  } catch (e) {
3154
3155
  const again = await this.store.getRun(run.id).catch(() => null);
3155
3156
  if (again) return this.recordOver(definition, again, run, evaluate);
3156
3157
  throw e;
3157
3158
  }
3158
3159
  if (!evaluate) return [];
3159
- await this.updateState(run.job, (before) => ({ state: holdRun(onRunStart(definition, run, before, this.now()), run.id), result: void 0 }));
3160
- if (run.status === "running") return [];
3161
- return this.finishRun(definition, run, this.now(), true);
3160
+ return this.recordOver(definition, inserted, run, true);
3162
3161
  }
3163
3162
  /** recordRun() for a run already stored. */
3164
3163
  async recordOver(definition, stored, run, evaluate) {
@@ -3166,7 +3165,15 @@ ${id}`;
3166
3165
  this.report(new Error(`run ${run.id} of ${run.job} belongs to job "${stored.job}"; ignored`), `recording ${run.job}`);
3167
3166
  return [];
3168
3167
  }
3169
- if (stored.status !== "running" && stored.status !== "timeout" || run.status === "running") return [];
3168
+ if (stored.status !== "running" && stored.status !== "timeout") return [];
3169
+ if (evaluate && stored.status === "running") {
3170
+ await this.updateState(run.job, async (before) => {
3171
+ const current = await this.store.getRun(run.id);
3172
+ if (!current || current.job !== run.job || current.status !== "running" || before.pendingRuns?.includes(run.id)) return { state: before, result: void 0 };
3173
+ return { state: holdRun(onRunStart(definition, run, before, this.now()), run.id), result: void 0 };
3174
+ });
3175
+ }
3176
+ if (run.status === "running") return [];
3170
3177
  const tracked = (await this.readState(run.job)).pendingRuns?.includes(run.id) ?? false;
3171
3178
  const claim = await this.claimFinish(run);
3172
3179
  if ("ignored" in claim) {