diff --git a/package.json b/package.json index db1fc80..ad11b3b 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "elasticsearch": "~11.0.1", - "lodash": "~4.11.1" + "lodash": "~4.11.1", + "puid": "~1.0.5" } } diff --git a/src/index.js b/src/index.js index dec50c3..c8b47fd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import events from 'events'; import createClient from './helpers/create_client'; import Job from './job.js'; +import Worker from './worker.js'; import { omit } from 'lodash'; export default class Elastique extends events.EventEmitter { @@ -24,4 +25,9 @@ export default class Elastique extends events.EventEmitter { const job = new Job(this, type, payload, options); return job; } + + registerWorker(type, workerFn) { + const worker = new Worker(this, type, workerFn); + return worker; + } } diff --git a/src/worker.js b/src/worker.js new file mode 100644 index 0000000..00f9c8e --- /dev/null +++ b/src/worker.js @@ -0,0 +1,15 @@ +import events from 'events'; +import Puid from 'puid'; + +export default class Job extends events.EventEmitter { + constructor(queue, type, workerFn) { + 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 + } +} \ No newline at end of file