@fungi.computer/watchdog 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -282,6 +282,16 @@ job ID. `wakeState(now)` still covers both partitions. These owner-local
282
282
  operations require no stored schema change and do not change the D1 or
283
283
  PostgreSQL adapters.
284
284
 
285
+ For owner-local SQLite, `pruneSettledJobs(owner, { lane, throughSequence })`
286
+ removes at most 500 settled rows at or below a durably consumed cursor. Supply
287
+ the minimum cursor of **every** consumer, including stopped consumers that may
288
+ resume. A missing cursor is zero. Queued, running and completing jobs survive.
289
+ Schedule another sweep when the returned count is 500. Owners that still read
290
+ selected terminal jobs can supply `retainFromSelect`, a trusted, parameterized
291
+ SQLite query selecting the job IDs to keep. This is host code, never caller SQL.
292
+ The host remains responsible for bounding that retained set and for preserving
293
+ its request replay contract after old jobs are removed.
294
+
285
295
  ## Shared D1 and PostgreSQL storage
286
296
 
287
297
  `@fungi.computer/watchdog/d1` exports `createD1Watchdog` and `watchdogD1Schema`.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as core from "./effect.js";
2
2
  export { WatchdogError } from "./internal/watchdog-error.js";
3
+ export { pruneSettledJobs } from "./internal/sqlite-store.js";
3
4
  export { WatchdogCompletingJobSchema, WatchdogCancellationIntentSchema, WatchdogCancellationResultSchema, WatchdogExecutionDecisionSchema, WatchdogIngestResultSchema, WatchdogQueuedJobSchema, WatchdogQueueHeadSchema, WatchdogReadResultSchema, WatchdogRunningJobSchema, WatchdogSettledJobSchema, WatchdogStoredJobSchema, } from "./effect.js";
4
5
  export type { EffectWatchdogOptions, EffectWatchdogExecutor, WatchdogCompletingJob, WatchdogCancellationDecision, WatchdogCancellationIntent, WatchdogCancellationResult, WatchdogExecutionDecision, WatchdogIngestResult, WatchdogLivenessUnknown, WatchdogLaneFailure, WatchdogLaneFailureResult, WatchdogQueuedJob, WatchdogQueueHead, WatchdogQueueProjector, WatchdogQueueTransition, WatchdogReadResult, WatchdogRunningJob, WatchdogRuntimeEffect, ConcurrentWatchdogRuntimeEffect, WatchdogSettledJob, WatchdogSqliteCursor, WatchdogSqliteOwner, WatchdogSqliteValue, WatchdogSqliteRow, WatchdogStoredJob, WatchdogTickResult, WatchdogTransactionalProjection, WatchdogWakeState, WatchdogRetryPolicy, WatchdogAttempt, } from "./effect.js";
5
6
  /** Promise host executor for one generic running job. */
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import * as core from "./effect.js";
6
6
  import { adaptPromiseWatchdogHost } from "./internal/promise-watchdog-host.js";
7
7
  import { WatchdogError } from "./internal/watchdog-error.js";
8
8
  export { WatchdogError } from "./internal/watchdog-error.js";
9
+ export { pruneSettledJobs } from "./internal/sqlite-store.js";
9
10
  export { WatchdogCompletingJobSchema, WatchdogCancellationIntentSchema, WatchdogCancellationResultSchema, WatchdogExecutionDecisionSchema, WatchdogIngestResultSchema, WatchdogQueuedJobSchema, WatchdogQueueHeadSchema, WatchdogReadResultSchema, WatchdogRunningJobSchema, WatchdogSettledJobSchema, WatchdogStoredJobSchema, } from "./effect.js";
10
11
  const runPromise = (effect) => Effect.runPromiseExit(effect).then((exit) => {
11
12
  if (Exit.isSuccess(exit))
@@ -1,6 +1,6 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import * as Schema from "effect/Schema";
3
- import type { WatchdogCompletingJob, WatchdogLaneFailure, WatchdogCancellationIntent, WatchdogCancellationResult, WatchdogExecutionDecision, WatchdogIngestResult, WatchdogQueuedJob, WatchdogQueueHead, WatchdogQueueProjector, WatchdogReadResult, WatchdogRunningJob, WatchdogSettledJob, WatchdogSettledRecord, WatchdogSqliteOwner, WatchdogSqliteRow, WatchdogStoredJob, WatchdogTransactionalProjection, WatchdogWakeState, WatchdogRetryPolicy, WatchdogAttempt } from "../effect.js";
3
+ import type { WatchdogCompletingJob, WatchdogLaneFailure, WatchdogCancellationIntent, WatchdogCancellationResult, WatchdogExecutionDecision, WatchdogIngestResult, WatchdogQueuedJob, WatchdogQueueHead, WatchdogQueueProjector, WatchdogReadResult, WatchdogRunningJob, WatchdogSettledJob, WatchdogSettledRecord, WatchdogSqliteOwner, WatchdogSqliteRow, WatchdogSqliteValue, WatchdogStoredJob, WatchdogTransactionalProjection, WatchdogWakeState, WatchdogRetryPolicy, WatchdogAttempt } from "../effect.js";
4
4
  import { WatchdogError } from "./watchdog-error.js";
5
5
  export type { WatchdogSqliteRow } from "../effect.js";
6
6
  export declare const laneFailureBatchSize = 256;
@@ -144,5 +144,21 @@ export declare const queuedHeadPredicate = "(cancellation_id IS NOT NULL OR NOT
144
144
  export declare const parseWakeTime: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => number;
145
145
  export declare function parseWakeState(raw: WatchdogSqliteRow | undefined): WatchdogWakeState;
146
146
  export declare function parseJobRow(raw: WatchdogSqliteRow): ParsedWatchdogSqliteJob;
147
+ /**
148
+ * Forget only settled rows at or below an owner's durably consumed cursor.
149
+ * The owner supplies the minimum of every consumer in this lane; omitted or
150
+ * uncommitted cursors must be treated as zero. Each sweep deletes at most 500.
151
+ */
152
+ export declare function pruneSettledJobs(owner: WatchdogSqliteOwner, input: Readonly<{
153
+ lane: string;
154
+ throughSequence: number;
155
+ limit?: number;
156
+ /** Trusted owner SQL selecting job IDs still read after settlement. May
157
+ * correlate with watchdog_jobs.queue_name; values remain bound parameters. */
158
+ retainFromSelect?: Readonly<{
159
+ text: string;
160
+ values: readonly WatchdogSqliteValue[];
161
+ }>;
162
+ }>): number;
147
163
  /** Construct Watchdog's private owner-local SQLite state. */
148
164
  export declare function openSqliteState(owner: WatchdogSqliteOwner, project?: WatchdogQueueProjector, partition?: LanePartition): WatchdogSqliteState;
@@ -192,6 +192,24 @@ function readSettled(owner, limit, afterSequence, partition, selectedLane) {
192
192
  return { sequence: parsed.row.sequence, job: parsed.job };
193
193
  });
194
194
  }
195
+ /**
196
+ * Forget only settled rows at or below an owner's durably consumed cursor.
197
+ * The owner supplies the minimum of every consumer in this lane; omitted or
198
+ * uncommitted cursors must be treated as zero. Each sweep deletes at most 500.
199
+ */
200
+ export function pruneSettledJobs(owner, input) {
201
+ const lane = Schema.decodeUnknownSync(laneSchema)(input.lane);
202
+ const through = Schema.decodeUnknownSync(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })))(input.throughSequence);
203
+ const limit = Schema.decodeUnknownSync(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 500 })))(input.limit ?? 500);
204
+ return owner.transactionSync(() => owner.sql
205
+ .exec(`DELETE FROM watchdog_jobs WHERE sequence IN (
206
+ SELECT sequence FROM watchdog_jobs
207
+ WHERE lane=? AND state='settled' AND sequence<=?
208
+ ${input.retainFromSelect === undefined ? "" : `AND job_id NOT IN (${input.retainFromSelect.text})`}
209
+ ORDER BY sequence LIMIT ?
210
+ ) RETURNING sequence`, lane, through, ...(input.retainFromSelect?.values ?? []), limit)
211
+ .toArray().length);
212
+ }
195
213
  function readQueueHead(owner, queue) {
196
214
  const raw = owner.sql
197
215
  .exec(`SELECT ${columns}
package/docs/api/index.md CHANGED
@@ -193,6 +193,29 @@ const Watchdog: WatchdogApi;
193
193
 
194
194
  Promise facade over the canonical Effect-owned runtime.
195
195
 
196
+ ## Functions
197
+
198
+ ### pruneSettledJobs()
199
+
200
+ ```ts
201
+ function pruneSettledJobs(owner, input): number;
202
+ ```
203
+
204
+ Forget only settled rows at or below an owner's durably consumed cursor. The
205
+ owner supplies the minimum of every consumer in this lane; omitted or
206
+ uncommitted cursors must be treated as zero. Each sweep deletes at most 500.
207
+
208
+ #### Parameters
209
+
210
+ | Parameter | Type |
211
+ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
212
+ | `owner` | [`WatchdogSqliteOwner`](effect.md#watchdogsqliteowner) |
213
+ | `input` | `Readonly`\<\{ `lane`: `string`; `throughSequence`: `number`; `limit?`: `number`; `retainFromSelect?`: `Readonly`\<\{ `text`: `string`; `values`: readonly [`WatchdogSqliteValue`](effect.md#watchdogsqlitevalue)[]; \}\>; \}\> |
214
+
215
+ #### Returns
216
+
217
+ `number`
218
+
196
219
  ## References
197
220
 
198
221
  ### WatchdogCompletingJobSchema
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/watchdog",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Payload-blind durable work scheduling and settlement core",
6
6
  "type": "module",