// Type definitions for node-resque 5.4 // Project: http://github.com/taskrabbit/node-resque // Definitions by: Gordey Doronin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// export interface ConnectionOptions { pkg?: string; host?: string; port?: number; database?: number; namespace?: string; looping?: boolean; options?: any; } export class Connection extends NodeJS.EventEmitter { constructor(options: ConnectionOptions); connect(): Promise; end(): Promise; } export interface Job { plugins?: string[]; pluginOptions?: { [pluginName: string]: any }; perform: (...args: any[]) => Promise; } export interface JobsHash { [jobName: string]: Job; } export interface QueueOptions { connection?: ConnectionOptions; } export class Queue extends NodeJS.EventEmitter { constructor(options: QueueOptions, jobs?: JobsHash); connect(): Promise; enqueue(queue: string, jobName: string, args: ReadonlyArray): Promise; enqueueIn(milliseconds: number, queue: string, jobName: string, args: ReadonlyArray): Promise; end(): Promise; on(event: 'error', cb: (error: Error, queue: string) => void): this; once(event: 'error', cb: (error: Error, queue: string) => void): this; } export interface WorkerOptions { connection?: ConnectionOptions; queues: string[]; name?: string; timeout?: number; looping?: boolean; } export type WorkerEvent = 'start' | 'end' | 'cleaning_worker' | 'poll' | 'ping' | 'job' | 'reEnqueue' | 'success' | 'failure' | 'error' | 'pause'; export class Worker extends NodeJS.EventEmitter { constructor(options: WorkerOptions, jobs?: JobsHash); connect(): Promise; start(): Promise; end(): Promise; on(event: 'start' | 'end' | 'pause', cb: () => void): this; on(event: 'cleaning_worker', cb: (worker: string, pid: string) => void): this; on(event: 'poll', cb: (queue: string) => void): this; on(event: 'ping', cb: (time: number) => void): this; on(event: 'job', cb: (queue: string, job: Job) => void): this; on(event: 'reEnqueue', cb: (queue: string, job: Job, plugin: string) => void): this; on(event: 'success', cb: (queue: string, job: Job, result: any) => void): this; on(event: 'failure', cb: (queue: string, job: Job, failure: any) => void): this; on(event: 'error', cb: (error: Error, queue: string, job: Job) => void): this; once(event: 'start' | 'end' | 'pause', cb: () => void): this; once(event: 'cleaning_worker', cb: (worker: string, pid: string) => void): this; once(event: 'poll', cb: (queue: string) => void): this; once(event: 'ping', cb: (time: number) => void): this; once(event: 'job', cb: (queue: string, job: Job) => void): this; once(event: 'reEnqueue', cb: (queue: string, job: Job, plugin: string) => void): this; once(event: 'success', cb: (queue: string, job: Job, result: any) => void): this; once(event: 'failure', cb: (queue: string, job: Job, failure: any) => void): this; once(event: 'error', cb: (error: Error, queue: string, job: Job) => void): this; removeAllListeners(event: WorkerEvent): this; } export interface SchedulerOptions { connection?: ConnectionOptions; name?: string; timeout?: number; stuckWorkerTimeout?: number; masterLockTimeout?: number; } export type SchedulerEvent = 'start' | 'end' | 'poll' | 'master' | 'cleanStuckWorker' | 'error' | 'workingTimestamp' | 'transferredJob'; export class Scheduler extends NodeJS.EventEmitter { constructor(options: SchedulerOptions, jobs?: JobsHash); connect(): Promise; start(): Promise; end(): Promise; on(event: 'start' | 'end' | 'poll' | 'master', cb: () => void): this; on(event: 'cleanStuckWorker', cb: (workerName: string, errorPayload: ErrorPayload, delta: number) => void): this; on(event: 'error', cb: (error: Error, queue: string) => void): this; on(event: 'workingTimestamp', cb: (timestamp: number) => void): this; on(event: 'transferredJob', cb: (timestamp: number, job: Job) => void): this; once(event: 'start' | 'end' | 'poll' | 'master', cb: () => void): this; once(event: 'cleanStuckWorker', cb: (workerName: string, errorPayload: ErrorPayload, delta: number) => void): this; once(event: 'error', cb: (error: Error, queue: string) => void): this; once(event: 'workingTimestamp', cb: (timestamp: number) => void): this; once(event: 'transferredJob', cb: (timestamp: number, job: Job) => void): this; removeAllListeners(event: SchedulerEvent): this; } export interface ErrorPayload { worker: string; queue: string; payload: any; exception: string; error: string; backtrace: string[]; failed_at: string; }