more stuff

This commit is contained in:
Boki 2026-10-20 20:11:40 -04:00
parent c3cb36c8d6
commit 7dec0be3b4
26 changed files with 1394 additions and 275 deletions

View file

@ -5,39 +5,65 @@ export interface RunIdentity {
runId: string;
backtestId: string;
}
export interface RunClaim extends RunIdentity {
attemptId: string;
config: BacktestConfig;
}
/** The runner owns this lifecycle. Results and terminal status must commit atomically. */
/** Every execution write must prove ownership of an unexpired attempt. */
export interface BacktestRunRepository {
start(config: BacktestConfig): Promise<RunIdentity>;
complete(result: BacktestRunResult): Promise<void>;
updateProgress(runId: string, progress: number, currentDate?: string): Promise<void>;
fail(runId: string, error: string): Promise<void>;
cancel(runId: string): Promise<void>;
start(config: BacktestConfig): Promise<RunClaim>;
load(runId: string): Promise<{ status: string; config: unknown } | null>;
rejectPending(runId: string, error: string): Promise<void>;
heartbeat(runId: string, attemptId: string): Promise<{ cancelRequested: boolean }>;
complete(result: BacktestRunResult, attemptId: string): Promise<void>;
updateProgress(
runId: string,
progress: number,
currentDate: string | undefined,
attemptId: string
): Promise<void>;
fail(runId: string, error: string, attemptId: string): Promise<void>;
cancel(runId: string, attemptId: string): Promise<void>;
updateControl(
runId: string,
update: { status?: 'running' | 'paused'; speedMultiplier?: number | null }
update: { status?: 'running' | 'paused'; speedMultiplier?: number | null },
attemptId: string
): Promise<void>;
}
export class BacktestConflictError extends Error {}
export class BacktestLeaseLostError extends BacktestConflictError {}
/** No database is never a license to execute an unowned job. */
export class UnavailableBacktestRunRepository implements BacktestRunRepository {
async start(_config: BacktestConfig): Promise<RunIdentity> {
private unavailable(): never {
throw new Error('Backtest execution requires a PostgreSQL run repository');
}
async complete(_result: BacktestRunResult): Promise<void> {
throw new Error('Backtest run repository is unavailable');
async start(_config: BacktestConfig): Promise<RunClaim> {
return this.unavailable();
}
async load(_runId: string): Promise<null> {
return this.unavailable();
}
async rejectPending(_runId: string, _error: string): Promise<void> {
this.unavailable();
}
async heartbeat(_runId: string, _attemptId: string): Promise<{ cancelRequested: boolean }> {
return this.unavailable();
}
async complete(_result: BacktestRunResult, _attemptId: string): Promise<void> {
this.unavailable();
}
async updateProgress(): Promise<void> {
throw new Error('Backtest run repository is unavailable');
this.unavailable();
}
async updateControl(): Promise<void> {
throw new Error('Backtest run repository is unavailable');
this.unavailable();
}
async fail(_runId: string, _error: string): Promise<void> {
throw new Error('Backtest run repository is unavailable');
async fail(_runId: string, _error: string, _attemptId: string): Promise<void> {
this.unavailable();
}
async cancel(_runId: string): Promise<void> {
throw new Error('Backtest run repository is unavailable');
async cancel(_runId: string, _attemptId: string): Promise<void> {
this.unavailable();
}
}