@sidequest/core
Version:
@sidequest/core is the core package of SideQuest, a distributed background job queue for Node.js and TypeScript applications.
42 lines (39 loc) • 1.74 kB
TypeScript
import { ErrorData } from '../schema/error-data.js';
import { JobData } from '../schema/job-data.js';
import { JobTransition } from './transition.js';
/**
* Transition for retrying a failed job.
*
* This transition will:
* - If the job has reached its maximum attempts, it will mark it as failed.
* - If not, it will log the reason for retrying, add the error to the job's errors,
* and set the job state to "waiting" with an available_at time
* based on an exponential backoff strategy.
* - The delay can be specified or calculated using exponential backoff with jitter.
*
* This transition can only be applied to jobs that are currently running.
*/
declare class RetryTransition extends JobTransition {
/** Optional delay in milliseconds before retrying. */
delay?: number;
/** The reason for retrying. */
reason: string | Error | ErrorData;
/**
* Creates a new RetryTransition.
* @param reason The reason for retrying.
* @param delay Optional delay in milliseconds before retrying.
*/
constructor(reason: ErrorData | Error | string, delay?: number);
apply(job: JobData): JobData;
/**
* Calculates the backoff delay for a retry attempt using exponential backoff with jitter.
*
* @param attempt - The current retry attempt number (1-based).
* @param baseDelay - The base delay in milliseconds for the first attempt. Defaults to 1000 ms.
* @param maxDelay - The maximum delay in milliseconds. Defaults to 3,600,000 ms (1 hour).
* @returns The calculated backoff delay in milliseconds, randomized with jitter and capped at maxDelay.
*/
private calculateBackoff;
shouldRun(job: JobData): boolean;
}
export { RetryTransition };