@midwayjs/bullmq
Version:
midway component for BullMQ
83 lines • 3.28 kB
TypeScript
import { BaseFramework, IMidwayBootstrapOptions, ILogger } from '@midwayjs/core';
import { Application, Context, IProcessor } from './interface';
import { Job, JobsOptions, Queue, Worker, QueueOptions, WorkerOptions, QueueEvents, QueueEventsProducer, QueueBaseOptions, QueueEventsOptions, FlowProducer } from 'bullmq';
export declare class BullMQQueue extends Queue {
protected queueName: string;
protected queueOptions: QueueOptions;
private queueEventsList;
private queueEventsProducerList;
constructor(queueName: string, queueOptions: QueueOptions);
addJobToQueue(data: any, options?: JobsOptions): Promise<Job>;
/**
* @deprecated use addJobToQueue instead
*/
runJob(data: any, options?: JobsOptions): Promise<Job>;
getQueueName(): string;
createQueueEvents(options?: QueueEventsOptions): QueueEvents;
getQueueEventsList(): QueueEvents[];
createQueueEventsProducer(options?: QueueBaseOptions): QueueEventsProducer;
getQueueEventsProducerList(): QueueEventsProducer[];
close(): Promise<void>;
}
export declare class BullMQFramework extends BaseFramework<Application, Context, any> {
private defaultConnection;
private defaultQueueConfig;
private defaultWorkerConfig;
private clearRepeatJobWhenStart;
private queueMap;
private workerMap;
private flowProducerMap;
protected bullMQLogger: ILogger;
applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
loadConfig(): void;
configure(): any;
getFrameworkName(): string;
run(): Promise<void>;
protected beforeStop(): Promise<void>;
/**
* Create a queue with name and queueOptions
*/
createQueue(name: string, queueOptions?: Partial<QueueOptions>): BullMQQueue;
/**
* Get a queue by name
*/
getQueue(name: string): BullMQQueue;
/**
* Ensure a queue by name and queueOptions
*/
protected ensureQueue(name: string, queueOptions?: Partial<QueueOptions>): BullMQQueue;
getQueueList(): BullMQQueue[];
/**
* Get the first worker by queueName
*/
getWorker(queueName: string): Worker;
/**
* Get all workers by queueName
*/
getWorkers(queueName: string): Worker[];
/**
* Create a worker
*/
createWorker(queueName: string, processor: (job: Job, token?: string) => Promise<any>, workerOptions?: Partial<WorkerOptions>): Worker;
/**
* Add a processor class and init a worker
*/
addProcessor(processor: new (...args: any[]) => IProcessor, queueName: string, workerOptions?: WorkerOptions): Promise<Worker<any, any, string>>;
/**
* Add a job to the queue
*/
addJobToQueue(queueName: string, jobData: any, options?: JobsOptions): Promise<Job | undefined>;
/**
* @deprecated use addJobToQueue instead
*/
runJob(queueName: string, jobData: any, options?: JobsOptions): Promise<Job | undefined>;
/**
* Create a flow producer, if producerName is provided, it will be store.
*/
createFlowProducer(options?: Partial<QueueBaseOptions>, producerName?: string): FlowProducer;
/**
* Get a flow producer by name
*/
getFlowProducer(producerName: string): FlowProducer | undefined;
}
//# sourceMappingURL=framework.d.ts.map