pass the entire queue to the Job instance

This commit is contained in:
2016-07-11 11:28:40 -07:00
parent a50dbf752e
commit 40d67829c8
2 changed files with 4 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ export default class Esqueue extends events.EventEmitter {
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) {

View File

@@ -9,13 +9,14 @@ const debug = logger('esqueue:job');
const puid = new Puid();
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 (!isPlainObject(payload)) throw new Error('Payload must be a plain object');
super();
this.client = options.client || client;
this.queue = queue;
this.client = options.client || this.queue.client;
this.id = puid.generate();
this.index = index;
this.jobtype = type;