Skip to content
Moleculer connector to faktory queue management (http://contribsys.com/faktory/)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Force error throw (For faktory to log error) Jun 15, 2019
test/unit
.codeclimate.yml
.editorconfig
.eslintrc.js First commit Apr 30, 2019
.gitignore First commit Apr 30, 2019
.npmignore First commit Apr 30, 2019
.travis.yml First commit Apr 30, 2019
LICENSE
README.md fix: Worker take only handlable jobs May 1, 2019
index.js First commit Apr 30, 2019
package-lock.json Lock update Jun 12, 2019
package.json

README.md

moleculer-faktory

Build Status Coverage Status Codacy Badge Maintainability David Known Vulnerabilities

Downloads FOSSA Status

How to use it

Worker (Service with your jobes)

const { WorkerMixin } = require('moleculer-faktory')

module.exports = {
  name: 'images',
  mixins: [WorkerMixin],
  settings: {
    faktory: {
      /** @type {String} Faktory url (tcp://:passqueue@localhost:7419/) also FAKTORY_URL can be use. */
      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 handler(ctx) {
        const { image, size } = ctx.params
        const { user } = ctx.meta
        // Do the magic here !
      }
    }
  }
}

Client (Service launching jobs)

const { ClientMixin } = require('moleculer-faktory')

module.exports = {
  name: 'web',
  mixins: [ClientMixin],
  settings: {
    faktory: {
      /** @type {String} Faktory url (tcp://:passqueue@localhost:7419/) also FAKTORY_URL can be use. */
      url: 'tcp://:passqueue@localhost:7419',
      /** @type {Object?} Additional options for `new Client()` */
      options: {
        labels: ['test'],
      }
    }
  },
  actions: {
    async 'image.upload'(ctx) {
      ctx.meta.user = {} // Meta will be passed to the job handler
      await this.queue(ctx, 'images.resize', { image: ctx.params.image, size: 'landscape.large' })
      return 'In progress...'
    }
  }
}

You can also use hooks (No native from faktory, middleware in this module : See src/worker.js#72)

const { ClientMixin } = require('moleculer-faktory')

module.exports = {
  name: 'web',
  mixins: [ClientMixin],
  settings: {
    faktory: {
      /** @type {String} Faktory url (tcp://:passqueue@localhost:7419/) also FAKTORY_URL can be use. */
      url: 'tcp://:passqueue@localhost:7419',
      /** @type {Object?} Additional options for `new Client()` */
      options: {
        labels: ['test'],
      }
    }
  },
  actions: {
    async 'image.upload'(ctx) {
      const { image } = ctx.params
      ctx.meta.user = {} // Meta will be passed to the job handler and also the hooks
      await this.queue(ctx, 'images.resize', { image: ctx.params.image, size: 'landscape.large' }, {
        start: { handler: 'web.image.start' },
        end: { handler: 'web.image.end', params: { image } }
      })
      return 'In progress...'
    },
    'image.start'() {
      // Automagicaly send to the client notification ?
    },
    'image.end'(ctx) {
      const { image } = ctx.params
      const { user } = ctx.meta
      // Automagicaly send to the client notification ?
    }
  }
}
You can’t perform that action at this time.