start on the worker logic
This commit is contained in:
@@ -1,15 +1,38 @@
|
||||
import events from 'events';
|
||||
import Puid from 'puid';
|
||||
import { jobStatuses } from './helpers/constants';
|
||||
|
||||
const puid = new Puid();
|
||||
|
||||
export default class Job extends events.EventEmitter {
|
||||
constructor(queue, type, workerFn) {
|
||||
constructor(queue, type, workerFn, opts = {}) {
|
||||
if (typeof type !== 'string') throw new Error('Type must be a string');
|
||||
if (typeof workerFn !== 'function') throw new Error('Worker must be a function');
|
||||
|
||||
super();
|
||||
const puid = new Puid();
|
||||
this.id = puid.generate();
|
||||
|
||||
// TODO: check for existing jobs to process
|
||||
this.id = puid.generate();
|
||||
this.queue = queue;
|
||||
this.client = this.queue.client;
|
||||
this.type = type;
|
||||
this.workerFn = workerFn;
|
||||
this.checkInterval = opts.interval || 1500;
|
||||
|
||||
this._processJobs();
|
||||
this._checker = setInterval(this._processJobs, this.checkInterval);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
clearInterval(this._checker);
|
||||
}
|
||||
|
||||
_processJobs() {
|
||||
const query = {};
|
||||
|
||||
return this.client.search({
|
||||
body: {
|
||||
query: query
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user