// Type definitions for pg-boss declare namespace PgBoss { interface Db { executeSql(text: string, values: any[]): Promise<{ rows: any[]; rowCount: number }>; } interface DatabaseOptions { application_name?: string; database?: string; user?: string; password?: string; host?: string; port?: number; schema?: string; ssl?: boolean; connectionString?: string; poolSize?: number; max?: number; db?: Db; } interface JobCreationOptions { uuid?: "v1" | "v4"; } interface JobFetchOptions { newJobCheckInterval?: number; newJobCheckIntervalSeconds?: number; } interface JobExpirationOptions { expireCheckInterval?: number; expireCheckIntervalSeconds?: number; expireCheckIntervalMinutes?: number; } interface JobArchiveOptions { archiveCompletedJobsEvery?: string; archiveCheckInterval?: number; archiveCheckIntervalSeconds?: number; archiveCheckIntervalMinutes?: number; deleteArchivedJobsEvery?: string; deleteCheckInterval?: number; } type ConstructorOptions = DatabaseOptions & JobCreationOptions & JobFetchOptions & JobExpirationOptions & JobArchiveOptions; interface PublishOptions { priority?: number; startAfter?: number | string | Date; singletonKey?: string; singletonSeconds?: number; singletonMinutes?: number; singletonHours?: number; singletonNextSlot?: boolean; retryLimit?: number; retryDelay?: number; retryBackoff?: boolean; expireIn?: string; } interface SubscribeOptions { teamSize?: number; teamConcurrency?: number; batchSize?: number; newJobCheckInterval?: number; newJobCheckIntervalSeconds?: number; } interface SubscribeHandler { (job: PgBoss.JobWithDoneCallback, done: PgBoss.JobDoneCallback): void; } interface Request { name: string; data?: object; options?: PublishOptions; } interface JobDoneCallback { (err?: Error | null, data?: T): void; } interface Job { id: string; name: string; data: T; } interface JobWithDoneCallback extends Job { done: JobDoneCallback; } interface MonitorStates { created: number; retry: number; active: number; completed: number; expired: number; cancelled: number; failed: number; queues: object; } } declare class PgBoss { constructor(connectionString: string); constructor(options: PgBoss.ConstructorOptions); static getConstructionPlans(schema: string): string; static getMigrationPlans(schema: string, version: string, uninstall: boolean): string; on(event: "error", handler: (error: Error) => void): void; on(event: "archived", handler: (count: number) => void): void; on(event: "expired", handler: (count: number) => void): void; on(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void): void; start(): Promise; stop(): Promise; connect(): Promise; disconnect(): Promise; publish(request: PgBoss.Request): Promise; publish(name: string, data: object): Promise; publish(name: string, data: object, options: PgBoss.PublishOptions): Promise; publishAfter(name: string, data: object, options: PgBoss.PublishOptions, date: Date): Promise; publishAfter(name: string, data: object, options: PgBoss.PublishOptions, dateString: string): Promise; publishAfter(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise; publishOnce(name: string, data: object, options: PgBoss.PublishOptions, key: string): Promise; publishThrottled(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise; publishThrottled(name: string, data: object, options: PgBoss.PublishOptions, seconds: number, key: string): Promise; publishDebounced(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise; publishDebounced(name: string, data: object, options: PgBoss.PublishOptions, seconds: number, key: string): Promise; subscribe(name: string, handler: PgBoss.SubscribeHandler): Promise; subscribe( name: string, options: PgBoss.SubscribeOptions, handler: PgBoss.SubscribeHandler ): Promise; unsubscribe(name: string): Promise; onComplete(name: string, handler: Function): Promise; onComplete(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise; offComplete(name: string): Promise; fetch(name: string): Promise | null>; fetch(name: string, batchSize: number): Promise[] | null>; fetchCompleted(name: string): Promise | null>; fetchCompleted(name: string, batchSize: number): Promise[] | null>; cancel(id: string): Promise; cancel(ids: string[]): Promise; complete(id: string): Promise; complete(id: string, data: object): Promise; complete(ids: string[]): Promise; fail(id: string): Promise; fail(id: string, data: object): Promise; fail(ids: string[]): Promise; deleteQueue(name: string): Promise; deleteAllQueues(): Promise; archive(): Promise; purge(): Promise; expire(): Promise; } export = PgBoss;