mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Update node-resque types to match v5.5.7. (#39973)
* Update Queue types Signed-off-by: petetnt <pete.a.nykanen@gmail.com> * Fix lint issues for Queue Signed-off-by: petetnt <pete.a.nykanen@gmail.com> * Add tests, small fixes Signed-off-by: petetnt <pete.a.nykanen@gmail.com> * Add redis as a connection parameter Signed-off-by: petetnt <pete.a.nykanen@gmail.com> * Add ConnectionOptions test for the redis parameter Signed-off-by: petetnt <pete.a.nykanen@gmail.com>
This commit is contained in:
committed by
Jesse Trinity
parent
f9c7b8f4d4
commit
2d1c6d8a70
Vendored
+42
-6
@@ -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 <https://github.com/gordey4doronin>
|
||||
// Definitions by: Gordey Doronin <https://github.com/gordey4doronin>, Pete Nykänen <https://github.com/petetnt>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
@@ -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<any>;
|
||||
};
|
||||
worker: string;
|
||||
}
|
||||
|
||||
export class Queue extends NodeJS.EventEmitter {
|
||||
constructor(options: QueueOptions, jobs?: JobsHash);
|
||||
|
||||
connect(): Promise<void>;
|
||||
enqueue(queue: string, jobName: string, args: ReadonlyArray<any>): Promise<void>;
|
||||
enqueueIn(milliseconds: number, queue: string, jobName: string, args: ReadonlyArray<any>): Promise<void>;
|
||||
end(): Promise<void>;
|
||||
|
||||
encode(queue: string, jobName: string, args?: ReadonlyArray<any>): string;
|
||||
enqueue(queue: string, jobName: string, args?: ReadonlyArray<any>): Promise<void>;
|
||||
enqueueAt(timestamp: number, queue: string, jobName: string, args?: ReadonlyArray<any>): Promise<void>;
|
||||
enqueueIn(milliseconds: number, queue: string, jobName: string, args?: ReadonlyArray<any>): Promise<void>;
|
||||
queues(): Promise<string[]>;
|
||||
delQueue(queue: string): Promise<void>;
|
||||
length(queue: string): Promise<number>;
|
||||
del(queue: string, jobName: string, args?: ReadonlyArray<any>, count?: number): Promise<number>;
|
||||
delDelayed(queue: string, jobName: string, args?: ReadonlyArray<any>, count?: number): Promise<number[]>;
|
||||
scheduledAt(queue: string, jobName: string, args?: ReadonlyArray<any>): Promise<number[]>;
|
||||
timestamps(): Promise<number[]>;
|
||||
delayedAt(timestamp: number): Promise<{ tasks: Array<Job<any>>, rTimestamp: number }>;
|
||||
queued(queue: string, start: number, stop: number): Promise<Array<Job<any>>>;
|
||||
allDelayed(): Promise<number[]>;
|
||||
locks(): Promise<{ [lockName: string]: string }>;
|
||||
delLock(lockName: string): Promise<number>;
|
||||
workers(): Promise<{ [hash: string]: string }>;
|
||||
workingOn(workerName: string, queues: string[]): Promise<WorkerStatus>;
|
||||
allWorkingOn(): Promise<{[hashName: string]: WorkerStatus }>;
|
||||
forceCleanWorker(workerName: string): Promise<ErrorPayload[]> | Promise<void>;
|
||||
cleanOldWorkers(age: number): Promise<{[workerName: string]: ErrorPayload} | {}>;
|
||||
failedCount(): Promise<number>;
|
||||
failed(start: number, stop: number): Promise<ErrorPayload[]>;
|
||||
removeFailed(failedJob: ErrorPayload): Promise<void>;
|
||||
retryAndRemoveFailed(failedJob: ErrorPayload): Promise<void>;
|
||||
stats(): Promise<any>;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class SubtractJob implements Job<number> {
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user