/** * Includes all the scripts needed by the queue and jobs. */ import { JobJson, JobJsonRaw, JobsOptions, RedisClient, KeepJobs } from '../interfaces'; import { JobState, FinishedStatus, FinishedPropValAttribute } from '../types'; import { Worker } from './worker'; import { QueueScheduler } from './queue-scheduler'; import { QueueBase } from './queue-base'; import { Job, MoveToChildrenOpts } from './job'; export declare type MinimalQueue = Pick; export declare type ParentOpts = { waitChildrenKey?: string; parentDependenciesKey?: string; parentKey?: string; }; export declare type JobData = [JobJsonRaw | number, string?]; export declare class Scripts { static isJobInList(queue: MinimalQueue, listKey: string, jobId: string): Promise; static addJob(client: RedisClient, queue: MinimalQueue, job: JobJson, opts: JobsOptions, jobId: string, parentOpts?: ParentOpts): Promise; static pause(queue: MinimalQueue, pause: boolean): Promise; static removeRepeatableArgs(queue: MinimalQueue, repeatJobId: string, repeatJobKey: string): string[]; static removeRepeatable(queue: MinimalQueue, repeatJobId: string, repeatJobKey: string): Promise; static remove(queue: MinimalQueue, jobId: string): Promise; static extendLock(queue: MinimalQueue, jobId: string, token: string, duration: number): Promise; static updateData(queue: MinimalQueue, job: Job, data: T): Promise; static updateProgress(queue: MinimalQueue, job: Job, progress: number | object): Promise; static moveToFinishedArgs(queue: MinimalQueue, job: Job, val: any, propVal: FinishedPropValAttribute, shouldRemove: boolean | number | KeepJobs, target: FinishedStatus, token: string, fetchNext?: boolean): string[]; private static moveToFinished; static finishedErrors(code: number, jobId: string, command: string, state?: string): Error; static drainArgs(queue: MinimalQueue, delayed: boolean): (string | number)[]; static drain(queue: MinimalQueue, delayed: boolean): Promise; static moveToCompleted(queue: MinimalQueue, job: Job, returnvalue: R, removeOnComplete: boolean | number | KeepJobs, token: string, fetchNext: boolean): Promise; static moveToFailedArgs(queue: MinimalQueue, job: Job, failedReason: string, removeOnFailed: boolean | number | KeepJobs, token: string, fetchNext?: boolean): string[]; static isFinished(queue: MinimalQueue, jobId: string, returnValue?: boolean): Promise; static getState(queue: MinimalQueue, jobId: string): Promise; static changeDelay(queue: MinimalQueue, jobId: string, delay: number): Promise; static changeDelayArgs(queue: MinimalQueue, jobId: string, timestamp: number): string[]; static moveToDelayedArgs(queue: MinimalQueue, jobId: string, timestamp: number, token: string): string[]; static moveToWaitingChildrenArgs(queue: MinimalQueue, jobId: string, token: string, opts?: MoveToChildrenOpts): string[]; static moveToDelayed(queue: MinimalQueue, jobId: string, timestamp: number, token?: string): Promise; /** * Move parent job to waiting-children state. * * @returns true if job is successfully moved, false if there are pending dependencies. * @throws JobNotExist * This exception is thrown if jobId is missing. * @throws JobLockNotExist * This exception is thrown if job lock is missing. * @throws JobNotInState * This exception is thrown if job is not in active state. */ static moveToWaitingChildren(queue: MinimalQueue, jobId: string, token: string, opts?: MoveToChildrenOpts): Promise; /** * Remove jobs in a specific state. * * @returns Id jobs from the deleted records. */ static cleanJobsInSet(queue: MinimalQueue, set: string, timestamp: number, limit?: number): Promise; static retryJobArgs(queue: MinimalQueue, job: Job): string[]; private static retryJobsArgs; static retryJobs(queue: MinimalQueue, state?: FinishedStatus, count?: number, timestamp?: number): Promise; /** * Attempts to reprocess a job * * @param queue - * @param job - * @param state - The expected job state. If the job is not found * on the provided state, then it's not reprocessed. Supported states: 'failed', 'completed' * * @returns Returns a promise that evaluates to a return code: * 1 means the operation was a success * 0 means the job does not exist * -1 means the job is currently locked and can't be retried. * -2 means the job was not found in the expected set */ static reprocessJob(queue: MinimalQueue, job: Job, state: 'failed' | 'completed'): Promise; static moveToActive(worker: Worker, token: string, jobId?: string): Promise<[] | [number | JobJsonRaw, string?]>; /** * It checks if the job in the top of the delay set should be moved back to the * top of the wait queue (so that it will be processed as soon as possible) */ static updateDelaySet(queue: MinimalQueue, delayedTimestamp: number): Promise<[number, string]>; static promote(queue: MinimalQueue, jobId: string): Promise; /** * Looks for unlocked jobs in the active queue. * * The job was being worked on, but the worker process died and it failed to renew the lock. * We call these jobs 'stalled'. This is the most common case. We resolve these by moving them * back to wait to be re-processed. To prevent jobs from cycling endlessly between active and wait, * (e.g. if the job handler keeps crashing), * we limit the number stalled job recoveries to settings.maxStalledCount. */ static moveStalledJobsToWait(queue: QueueScheduler): Promise; static obliterate(queue: MinimalQueue, opts: { force: boolean; count: number; }): Promise; } export declare function raw2jobData(raw: any[]): [JobJsonRaw | number, string?] | [];