Files
tbenandClaude Opus 5.5 938a1da71d Add queue tables, quote SQL identifiers (v1.3.0)
- isQueue table option adds queue columns and a (status, available_at)
  index; BunSQLite.queue exposes add, claim, complete, fail and
  release_stale with atomic claims
- Set busy_timeout on connections so workers in separate processes wait
  instead of failing with SQLITE_BUSY
- Quote table and column names with backticks in generated SQL, so
  reserved words (to, order, group) work and unknown columns error
  instead of matching as string literals
- Tests for queue ops, multi-process claims and reserved-word names

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 16:29:14 +01:00

65 lines
2.1 KiB
TypeScript

import type { APIResponseObject, BunSQLiteConfig } from "../../types";
type BaseParams<Table extends string = string> = {
table: Table;
config?: BunSQLiteConfig;
};
/**
* # Add jobs to a queue table
* @description `delay` (ms) holds the jobs back before they can be claimed
*/
export declare function QueueAdd<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, data, delay, config, }: BaseParams<Table> & {
data: Schema[];
delay?: number;
}): Promise<APIResponseObject<Schema>>;
/**
* # Claim jobs from a queue table
* @description Claimed jobs are set to `processing` in one statement, so
* two workers can never claim the same job. Stale locks are released first.
*/
export declare function QueueClaim<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, worker, limit, config, }: BaseParams<Table> & {
worker?: string;
limit?: number;
}): Promise<APIResponseObject<Schema>>;
/**
* # Mark a claimed job as done
* @description Deletes the job instead when `deleteOnComplete` is set
*/
export declare function QueueComplete<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, id, config, }: BaseParams<Table> & {
id: number | string;
}): Promise<APIResponseObject<Schema>>;
/**
* # Mark a claimed job as failed
* @description The job goes back to `pending` with an exponential
* `backoff` delay, or to `failed` once it has used `maxAttempts`
*/
export declare function QueueFail<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, id, error, config, }: BaseParams<Table> & {
id: number | string;
error?: string;
}): Promise<APIResponseObject<Schema>>;
/**
* # Release stale locks
* @description For jobs whose worker died. `claim` also does this.
*/
export declare function QueueReleaseStale<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, config }: BaseParams<Table>): Promise<APIResponseObject<Schema>>;
export {};