@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.d.cts CHANGED
@@ -11,7 +11,7 @@ export { a as AlertChannel, d as AlertDetails, e as AlertType, B as BudgetBreach
11
11
  declare function memory(): Store & Required<Pick<Store, "lastRun">>;
12
12
 
13
13
  /** This release of @cronwatch/sdk. scripts/release.mjs keeps it in step with package.json. */
14
- declare const VERSION = "0.14.1";
14
+ declare const VERSION = "0.14.2";
15
15
 
16
16
  /**
17
17
  * "15m" -> 900000. Accepts a plain number of milliseconds, and compound
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { a as AlertChannel, d as AlertDetails, e as AlertType, B as BudgetBreach
11
11
  declare function memory(): Store & Required<Pick<Store, "lastRun">>;
12
12
 
13
13
  /** This release of @cronwatch/sdk. scripts/release.mjs keeps it in step with package.json. */
14
- declare const VERSION = "0.14.1";
14
+ declare const VERSION = "0.14.2";
15
15
 
16
16
  /**
17
17
  * "15m" -> 900000. Accepts a plain number of milliseconds, and compound
package/dist/index.js CHANGED
@@ -720,7 +720,7 @@ function onCheck(def, stored, lastRun, state, now) {
720
720
  return { state: next, alerts, nextExpectedAt, dueAt: exp.dueAt };
721
721
  }
722
722
  function isStuck(def, run, now) {
723
- return run.status === "running" && now - run.startedAt > timeoutMs(def);
723
+ return run.status === "running" && run.finishedAt === null && now - run.startedAt > timeoutMs(def);
724
724
  }
725
725
  function muteOpens(previous, next) {
726
726
  const muted = cloneState(next);
@@ -1216,7 +1216,7 @@ function staticAsset(path, base) {
1216
1216
  }
1217
1217
 
1218
1218
  // src/version.ts
1219
- var VERSION = "0.14.1";
1219
+ var VERSION = "0.14.2";
1220
1220
  var API_VERSION = 1;
1221
1221
 
1222
1222
  // src/routes/timeline.ts
@@ -3146,17 +3146,16 @@ ${id}`;
3146
3146
  const definition = toStored(declared);
3147
3147
  const stored = await this.store.getRun(run.id);
3148
3148
  if (stored) return this.recordOver(definition, stored, run, evaluate);
3149
+ const inserted = evaluate ? { ...run, status: "running" } : run;
3149
3150
  try {
3150
- await this.store.insertRun(run);
3151
+ await this.store.insertRun(inserted);
3151
3152
  } catch (e) {
3152
3153
  const again = await this.store.getRun(run.id).catch(() => null);
3153
3154
  if (again) return this.recordOver(definition, again, run, evaluate);
3154
3155
  throw e;
3155
3156
  }
3156
3157
  if (!evaluate) return [];
3157
- await this.updateState(run.job, (before) => ({ state: holdRun(onRunStart(definition, run, before, this.now()), run.id), result: void 0 }));
3158
- if (run.status === "running") return [];
3159
- return this.finishRun(definition, run, this.now(), true);
3158
+ return this.recordOver(definition, inserted, run, true);
3160
3159
  }
3161
3160
  /** recordRun() for a run already stored. */
3162
3161
  async recordOver(definition, stored, run, evaluate) {
@@ -3164,7 +3163,15 @@ ${id}`;
3164
3163
  this.report(new Error(`run ${run.id} of ${run.job} belongs to job "${stored.job}"; ignored`), `recording ${run.job}`);
3165
3164
  return [];
3166
3165
  }
3167
- if (stored.status !== "running" && stored.status !== "timeout" || run.status === "running") return [];
3166
+ if (stored.status !== "running" && stored.status !== "timeout") return [];
3167
+ if (evaluate && stored.status === "running") {
3168
+ await this.updateState(run.job, async (before) => {
3169
+ const current = await this.store.getRun(run.id);
3170
+ if (!current || current.job !== run.job || current.status !== "running" || before.pendingRuns?.includes(run.id)) return { state: before, result: void 0 };
3171
+ return { state: holdRun(onRunStart(definition, run, before, this.now()), run.id), result: void 0 };
3172
+ });
3173
+ }
3174
+ if (run.status === "running") return [];
3168
3175
  const tracked = (await this.readState(run.job)).pendingRuns?.includes(run.id) ?? false;
3169
3176
  const claim = await this.claimFinish(run);
3170
3177
  if ("ignored" in claim) {