// Type definitions for node-resque 5.5 // Project: http://github.com/taskrabbit/node-resque // Definitions by: Gordey Doronin , Pete Nykänen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 /// import { EventEmitter } from 'events'; export interface ConnectionOptions { pkg?: string; host?: string; port?: number; database?: number; namespace?: string; looping?: boolean; options?: any; redis?: any; } export class Connection extends 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 interface WorkerStatus { run_at: string; queue: string; payload: { class: string; queue: string; args: ReadonlyArray; }; worker: string; } export class Queue extends EventEmitter { constructor(options: QueueOptions, jobs?: JobsHash); connect(): Promise; end(): Promise; encode(queue: string, jobName: string, args?: ReadonlyArray): string; enqueue(queue: string, jobName: string, args?: ReadonlyArray): Promise; enqueueAt(timestamp: number, queue: string, jobName: string, args?: ReadonlyArray): Promise; enqueueIn(milliseconds: number, queue: string, jobName: string, args?: ReadonlyArray): Promise; queues(): Promise; delQueue(queue: string): Promise; length(queue: string): Promise; del(queue: string, jobName: string, args?: ReadonlyArray, count?: number): Promise; delDelayed(queue: string, jobName: string, args?: ReadonlyArray, count?: number): Promise; scheduledAt(queue: string, jobName: string, args?: ReadonlyArray): Promise; timestamps(): Promise; delayedAt(timestamp: number): Promise<{ tasks: Array>, rTimestamp: number }>; queued(queue: string, start: number, stop: number): Promise>>; allDelayed(): Promise; locks(): Promise<{ [lockName: string]: string }>; delLock(lockName: string): Promise; workers(): Promise<{ [hash: string]: string }>; workingOn(workerName: string, queues: string[]): Promise; allWorkingOn(): Promise<{[hashName: string]: WorkerStatus }>; forceCleanWorker(workerName: string): Promise | Promise; cleanOldWorkers(age: number): Promise<{[workerName: string]: ErrorPayload} | {}>; failedCount(): Promise; failed(start: number, stop: number): Promise; removeFailed(failedJob: ErrorPayload): Promise; retryAndRemoveFailed(failedJob: ErrorPayload): Promise; stats(): 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 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 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[] | null; failed_at: string; }