nats-jobs
Version:
Background job processor using NATS
36 lines (35 loc) • 1.04 kB
TypeScript
import { ConnectionOptions } from 'nats';
import { JobDef, Events } from './types';
import EventEmitter from 'eventemitter3';
/**
* Call `start` to begin processing jobs based on def. To
* gracefully shutdown call `stop` method.
*/
export declare const jobProcessor: (opts?: ConnectionOptions) => Promise<{
/**
* Call perform for each message received on the stream.
*/
start: (def: JobDef) => {
/**
* To be used in conjunction with SIGTERM and SIGINT.
*
* ```ts
* const processor = await jobProcessor()
* const stop = processor.start({})
* const shutDown = async () => {
* await stop()
* process.exit(0)
* }
*
* process.on('SIGTERM', shutDown)
* process.on('SIGINT', shutDown)
* ```
*/
stop: () => Promise<void>;
};
/**
* Call stop on all jobs and close the NATS connection.
*/
stop: () => Promise<void>;
emitter: EventEmitter<Events, any>;
}>;