import type { ImportDeps } from '../deps.js'; import type { ValidationContext } from '../entities/definition.js'; import type { IssuePhase, JobCounts, JobStage, JobStatus } from '../job/types.js'; import type { ImportJob } from '../job/types.js'; import type { CsvLimits } from '../reader/readCsv.js'; import { IssueSink } from './issueSink.js'; /** How a run ended; the caller (the worker's `main`) turns it into an exit code. */ export type RunOutcome = 'validated' | 'completed' | 'stopped' | 'failed' | 'canceled' | 'interrupted' /** Someone else claimed the job first, or it is gone: nothing was done. */ | 'not_claimed' /** The job was deleted, canceled, declared dead or claimed again: the worker stopped, and wrote nothing more. */ | 'lost'; export interface RunResult { outcome: RunOutcome; counts?: JobCounts; message?: string; } export interface RunOptions { /** `host:pid`, for diagnosis. */ worker?: string; /** Aborted by SIGTERM: the run finishes its row and ends `interrupted`. */ signal?: AbortSignal; } export type StopReason = 'cancel' | 'lost' | 'interrupted'; /** Why the run has to stop; the first reason stays. */ export declare class RunControl { readonly controller: AbortController; reason: StopReason | null; stop(reason: StopReason): void; get signal(): AbortSignal; } export declare function validationLimits(deps: ImportDeps): Partial; export declare function validationContext(deps: ImportDeps, job: ImportJob, /** * Set by the check of an upload (not the check at the start of an import, D-33, * which does not fetch images): with the box "Check that image URLs can be * reached" ticked, the check asks for the images (IMG-05). */ probing?: { signal: AbortSignal; }): ValidationContext; /** * One run of one job by one worker: the claim it was given, the counts and the * problems it has collected, and the heartbeat that writes them (§ 8.4). The * heartbeat is on a timer, every 2 seconds, and not in the row loop, so that a * long row (a slow image) does not look like a dead worker. */ export declare class Session { readonly deps: ImportDeps; readonly job: ImportJob; readonly attempt: number; private readonly outer?; readonly control: RunControl; readonly sinks: { validate: IssueSink; import: IssueSink; }; counts: JobCounts; stage: JobStage | null; private stopTimer; private ticking; private readonly owned; /** Rows written again by a resumed run, whose old problems the next checkpoint replaces. */ private superseded; private chain; private readonly onAbort; constructor(deps: ImportDeps, job: ImportJob, attempt: number, counts: JobCounts, outer?: AbortSignal | undefined); start(): void; /** * Writes the counts, the stage and the new problems in one step. False when * the job is no longer ours (the run is then told to stop) or when the write * failed (the problems are kept for the next try). */ flush(): Promise; private write; /** * Tells the job that the run waits for the event queue, or that it does not * any more (`waiting_since`, § 8.5). False when the job is no longer ours (the * run is then told to stop). A write that fails is logged and does not stop * the run: the wait itself does not depend on it, only the hint on the page. */ setWaiting(waiting: boolean): Promise; /** A resumed run wrote this row again: its old problems go with the next checkpoint. */ supersede(rowNumber: number): void; /** * Starts a phase from the beginning: the totals of an earlier run of it are * gone, and this run's problems and cap flag are the ones that count. A phase * the run does not begin is left as it was (a check must not clear the flag of * an import that was cut at the cap): `currentCounts` takes the flag of the * phases the run owns, and only those, from the sinks. */ beginPhase(phase: IssuePhase): void; /** The counts as they are now, with whether (and from where) the problems were cut at the cap. */ private currentCounts; /** * Stops the timer. A write that is under way goes on, and the next one waits * for it (`flush` chains them), so the order of the writes is kept. */ stopHeartbeat(): void; /** The job is no longer ours: stops without a write. */ abandon(): Promise; /** * Ends the run. A reason to stop that came in the meantime (a cancel, a * SIGTERM) wins over `to` unless the run failed. A job that is no longer ours * gets no write at all. */ finish(to: JobStatus, message?: string | null): Promise; } /** The text of a failure for the admin (J1, J2, J3). */ export declare function failureMessage(error: unknown): string;