pass the entire queue to the Job instance
This commit is contained in:
@@ -49,7 +49,7 @@ export default class Esqueue extends events.EventEmitter {
|
|||||||
indexSettings: this.settings.indexSettings,
|
indexSettings: this.settings.indexSettings,
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Job(this.client, index, type, payload, options);
|
return new Job(this, index, type, payload, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerWorker(type, workerFn, opts) {
|
registerWorker(type, workerFn, opts) {
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ const debug = logger('esqueue:job');
|
|||||||
const puid = new Puid();
|
const puid = new Puid();
|
||||||
|
|
||||||
export default class Job extends events.EventEmitter {
|
export default class Job extends events.EventEmitter {
|
||||||
constructor(client, index, type, payload, options = {}) {
|
constructor(queue, index, type, payload, options = {}) {
|
||||||
if (typeof type !== 'string') throw new Error('Type must be a string');
|
if (typeof type !== 'string') throw new Error('Type must be a string');
|
||||||
if (!isPlainObject(payload)) throw new Error('Payload must be a plain object');
|
if (!isPlainObject(payload)) throw new Error('Payload must be a plain object');
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.client = options.client || client;
|
this.queue = queue;
|
||||||
|
this.client = options.client || this.queue.client;
|
||||||
this.id = puid.generate();
|
this.id = puid.generate();
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.jobtype = type;
|
this.jobtype = type;
|
||||||
|
|||||||
Reference in New Issue
Block a user