@backgroundjs/core
Version:
An extendible background job queue for js/ts applications
72 lines • 2.14 kB
TypeScript
import { Pool } from "pg";
import { JobStorage } from "./base-storage.js";
import { Job, JobStatus } from "../types.js";
/**
* PostgreSQL storage adapter for JobQueue
*
* This storage adapter uses PostgreSQL to store jobs, making it suitable
* for distributed environments with multiple instances/processes.
*/
export declare class PostgreSQLJobStorage implements JobStorage {
private readonly pool;
private readonly tableName;
private initialized;
private readonly logging;
private readonly staleJobTimeout;
/**
* Create a new PostgreSQL job storage
*
* @param pool - A pg Pool instance
* @param options - Configuration options
*/
constructor(pool: Pool, options?: {
tableName?: string;
logging?: boolean;
staleJobTimeout?: number;
});
/**
* Initialize the database tables if they don't exist
*/
initialize(): Promise<void>;
/**
* Save a job to PostgreSQL
*/
saveJob(job: Job): Promise<void>;
/**
* Get a job by ID
*/
getJob(id: string): Promise<Job | null>;
/**
* Get jobs by status
*/
getJobsByStatus(status: JobStatus): Promise<Job[]>;
/**
* Update a job
*/
updateJob(job: Job): Promise<void>;
/**
* Acquire the next pending job
* @returns The next pending job, or null if no pending jobs are available
*/
acquireNextJob(handlerNames: string[]): Promise<Job | null>;
acquireNextJobs(batchSize: number, handlerNames?: string[]): Promise<Job[]>;
/**
* Complete a job
* @param jobId - The ID of the job to complete
* @param result - The result of the job
*/
completeJob(jobId: string, result: any): Promise<void>;
/**
* Fail a job
* @param jobId - The ID of the job to fail
* @param error - The error message
*/
failJob(jobId: string, error: string): Promise<void>;
/**
* Map a database row to a Job object
* @param row - The database row to map
* @returns The mapped Job object
*/
private mapRowToJob;
}
//# sourceMappingURL=postgresql-storage.d.ts.map