@penkov/tasks_queue
Version:
A lightweight PostgreSQL-backed task queue system with scheduling, retries, backoff strategies, and priority handling. Designed for efficiency and observability in modern Node.js applications.
94 lines (93 loc) • 2.53 kB
TypeScript
import "reflect-metadata";
import { BackoffType, MissedRunStrategy } from "./tasks-model.js";
/**
* Metadata key that marks methods with periodic task schedule definition.
*/
export declare const TASKS_QUEUE_SCHEDULED_TASK_METADATA: unique symbol;
interface ScheduledTaskBaseOptions {
/**
* Unique periodic task name used for deduplication.
*/
name: string;
/**
* Queue that should receive periodic task runs.
*/
queue: string;
/**
* Optional pool where the method worker should be registered.
* Defaults to `default`.
*/
pool?: string;
/**
* Optional initial start time.
*/
startAfter?: Date;
/**
* Optional task priority.
*/
priority?: number;
/**
* Optional payload passed to the worker.
*/
payload?: object;
/**
* Optional per-attempt timeout in milliseconds.
*/
timeout?: number;
/**
* Optional maximum attempts.
*/
retries?: number;
/**
* Optional retry backoff in milliseconds.
*/
backoff?: number;
/**
* Optional retry backoff type.
*/
backoffType?: BackoffType;
/**
* Optional periodic missed-run strategy.
*/
missedRunStrategy?: MissedRunStrategy;
/**
* If true, replaces an existing periodic task with the same name.
*/
replaceExisting?: boolean;
}
export interface ScheduledCronTaskOptions extends ScheduledTaskBaseOptions {
/**
* Cron expression for periodic scheduling.
*/
cron: string;
fixedRate?: never;
fixedDelay?: never;
}
export interface ScheduledFixedRateTaskOptions extends ScheduledTaskBaseOptions {
/**
* Fixed-rate interval in milliseconds.
*/
fixedRate: number;
cron?: never;
fixedDelay?: never;
}
export interface ScheduledFixedDelayTaskOptions extends ScheduledTaskBaseOptions {
/**
* Fixed-delay interval in milliseconds.
*/
fixedDelay: number;
cron?: never;
fixedRate?: never;
}
/**
* Method-level schedule definition discovered via NestJS providers.
*/
export type ScheduledTaskOptions = ScheduledCronTaskOptions | ScheduledFixedRateTaskOptions | ScheduledFixedDelayTaskOptions;
/**
* Mark a provider method with a periodic schedule declaration.
*
* The decorator declares schedule metadata and auto-registers the decorated
* method as a queue worker during NestJS module initialization.
*/
export declare const ScheduledTask: (options: ScheduledTaskOptions) => MethodDecorator;
export {};