moleculer-faktory
How to use it
Worker (Service with your jobes)
const WorkerMixin = moduleexports = name: 'images' mixins: WorkerMixin settings: faktory: /** @type*/ url: 'tcp://:passqueue@localhost:7419' /** @type {Object?} Additional options for `new Worker()` */ options: concurrency: 5 timeout: 25 * 1000 /** @type {Array?} Middlewares for faktory */ middlewares: /** @type {Boolean?} Enable hooks middleware */ hooks: true actions: resize: queue: true async { const image size = ctxparams const user = ctxmeta // Do the magic here ! }
Client (Service launching jobs)
const ClientMixin = moduleexports = name: 'web' mixins: ClientMixin settings: faktory: /** @type*/ url: 'tcp://:passqueue@localhost:7419' /** @type {Object?} Additional options for `new Client()` */ options: labels: 'test' actions: async 'image.upload'ctx ctxmetauser = {} // Meta will be passed to the job handler await this return 'In progress...'
You can also use hooks (No native from faktory, middleware in this module : See src/worker.js#72)
const ClientMixin = moduleexports = name: 'web' mixins: ClientMixin settings: faktory: /** @type*/ url: 'tcp://:passqueue@localhost:7419' /** @type {Object?} Additional options for `new Client()` */ options: labels: 'test' actions: async 'image.upload'ctx const image = ctxparams ctxmetauser = {} // Meta will be passed to the job handler and also the hooks await this return 'In progress...' 'image.start' // Automagicaly send to the client notification ? 'image.end'ctx const image = ctxparams const user = ctxmeta // Automagicaly send to the client notification ?