diff --git a/types/node-resque/index.d.ts b/types/node-resque/index.d.ts index 4b09807ee5..d795cae08c 100644 --- a/types/node-resque/index.d.ts +++ b/types/node-resque/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for node-resque 5.4 +// Type definitions for node-resque 5.5 // Project: http://github.com/taskrabbit/node-resque -// Definitions by: Gordey Doronin +// Definitions by: Gordey Doronin , Pete Nykänen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 /// @@ -13,6 +14,7 @@ export interface ConnectionOptions { namespace?: string; looping?: boolean; options?: any; + redis?: any; } export class Connection extends NodeJS.EventEmitter { @@ -36,14 +38,48 @@ 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 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; - + 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; } @@ -126,6 +162,6 @@ export interface ErrorPayload { payload: any; exception: string; error: string; - backtrace: string[]; + backtrace: string[] | null; failed_at: string; } diff --git a/types/node-resque/node-resque-tests.ts b/types/node-resque/node-resque-tests.ts index 4e09b54851..912a124265 100644 --- a/types/node-resque/node-resque-tests.ts +++ b/types/node-resque/node-resque-tests.ts @@ -22,6 +22,7 @@ class SubtractJob implements Job { } const connection: ConnectionOptions = { host: 'localhost', port: 6379 }; +const connectionWithCustomRedis: ConnectionOptions = { redis: "fake_redis_client" }; const queues = ['math', 'otherQueue']; const jobs: JobsHash = { add: new AddJob(), @@ -64,9 +65,41 @@ worker.connect().then(() => worker.start()); // start scheduler scheduler.connect().then(() => scheduler.start()); -queue.connect().then(() => { +queue.connect().then(async () => { queue.enqueue('math', 'add', [1, 2]); queue.enqueue('math', 'add', [1, 2]); queue.enqueue('math', 'add', [2, 3]); queue.enqueueIn(3000, 'math', 'subtract', [2, 1]); + queue.enqueueAt(3000, 'math', 'substract', [2, 1]); + + const stats = queue.stats(); + const queues = queue.queues(); + await queue.delQueue('math'); + + const length = await queue.length('math'); + const numberOfJobsDeleted = await queue.del('math', 'add', undefined, 6); + const timestamps = await queue.delDelayed('math', 'add', [1, 2]); + const scheduledAt = await queue.scheduledAt('math', 'add', [1, 2]); + + const timestamps2 = await queue.timestamps(); + const jobsEnqueuedForThisTimestamp = await queue.delayedAt(timestamps2[0]); + const jobs = queue.allDelayed(); + + const workers = await queue.workers(); + const workerStatus = await queue.workingOn('math', ['foo', 'bar']); + const details = await queue.allWorkingOn(); + const failedCount = await queue.failedCount(); + + const failedJob = { + worker: 'busted-worker-3', + queue: 'busted-queue', + payload: { class: 'busted_job', queue: 'busted-queue', args: [ 1, 2, 3 ] }, + exception: 'ERROR_NAME', + error: 'I broke', + failed_at: 'Sun Apr 26 2015 14:00:44 GMT+0100 (BST)', + backtrace: ['killed by', 'queue#forceCleanWorker'], + }; + + await queue.removeFailed(failedJob); + await queue.retryAndRemoveFailed(failedJob); });