@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
62 lines • 3.58 kB
TypeScript
/**
* State transitions of scheduled jobs: claim an occurrence, re-arm a recurring job, settle an
* occurrence, cancel a job. Every transition that could bring a job back re-checks the job's
* tombstone AFTER its write and undoes the write when a cancel won, so cancellation is final.
*/
import { type JobListing, type RunnerIdentity } from "./store.ts";
import { type ScheduledJob } from "./types.ts";
export interface CancelResult {
readonly job: ScheduledJob;
/** True when an occurrence was already being delivered; that one delivery may still complete. */
readonly inFlight: boolean;
/** Failed occurrence records removed with the job. */
readonly removedFailed: number;
}
/**
* Cancels a job for good: writes its tombstone, then removes its pending job and failed records.
* With `sessionId`, only that session's job may be cancelled. Returns undefined when no such job
* exists (or it belongs to another session). An occurrence already being delivered cannot be
* recalled; `inFlight` says so, and nothing after it will re-arm, deliver, or record the job.
*/
export declare function cancelScheduledJob(dir: string, id: string, options?: {
readonly sessionId?: string;
}): Promise<CancelResult | undefined>;
export declare function occurrenceFile(id: string, occurrence: number, owner: RunnerIdentity): string;
/**
* Puts a record taken by mistake back into `pending/` without ever overwriting a pending file
* (`link` fails with EEXIST instead), then re-checks the tombstone like every other re-arm.
*/
export declare function restorePending(dir: string, record: string, id: string): Promise<void>;
/**
* Claims occurrence `job.fireCount + 1` of a pending job for `owner` by an atomic rename.
* Returns the store-relative occurrence record, or undefined when another runner claimed it first,
* the job was cancelled, or the pending file is not the generation `job` describes (it is then put
* back untouched).
*/
export declare function claimOccurrence(dir: string, job: ScheduledJob, owner: RunnerIdentity): Promise<string | undefined>;
/**
* Re-arms a recurring job in `pending/` before its claimed occurrence is delivered. The tombstone
* is re-checked after the write, so a cancel racing this re-arm always wins.
*/
export declare function rearmRecurringJob(dir: string, next: ScheduledJob): Promise<void>;
/**
* Re-arms a recurring job whose runner died after claiming occurrence `occurrence` but before its
* re-arm, so a crash in that window loses the occurrence, never the schedule. Nothing happens when
* the job was cancelled, is pending again, or has a later occurrence on record (the re-arm ran);
* the exclusive `link` never overwrites a pending file another runner restored first. Returns the
* restored job.
*/
export declare function restoreAbandonedSchedule(dir: string, job: ScheduledJob, occurrence: number, now: number): Promise<ScheduledJob | undefined>;
/**
* Ends a claimed occurrence: removed on delivery, kept in `failed/` with the error otherwise -
* unless the job was cancelled meanwhile, in which case nothing about it is kept.
*/
export declare function settleOccurrence(dir: string, record: string, job: ScheduledJob, occurrence: number, outcome: {
readonly ok: true;
} | {
readonly ok: false;
readonly error: string;
}): Promise<void>;
/** Removes tombstones older than a day whose job left no pending or firing record behind. */
export declare function pruneTombstones(dir: string, listing: JobListing, now: number): Promise<void>;
//# sourceMappingURL=occurrences.d.ts.map