Interface to many worker queue backends.
One interface to many queue & worker backends.
npm install que
var Que = require'que';Queconnect'gear'// all backends connected;Quedisconnect// all backends disconnected;
var EchoReverseWorker = Quedefinejob: 'echoReverse' // job namedriver: 'gearman' // driver's name// processing functionvar result = thisparamsmessagesplit''reversejoin''; // this.params contains all the data you send, let's just reverse the stringcallbackfalse echo: result ; // first argument specifies error(none, in our case), second - response;
EchoReverseWorkersubmit message: '2pac' // second argument is optionalresponseecho == 'cap2'; // true;
You can define workers using CoffeeScript native class system:
class EchoReverseWorker extends Que.Workerjob: 'echoReverse'driver: 'gearman'process: (callback) ->result = @params.message.split('').reverse().join('')callback false, echo: resultEchoReverseWorker = Que.Workers.setup EchoReverseWorker # this is required
Your driver should implement this interface:
class SomeDriver@connect: (server, callback) -># server is an URI, like protocol://127.0.0.1:1234# callback should be called when you connect to a backend@disconnect: (callback) -># callback should be called when you disconnect from a backend@register: (name, handler) -># name is the name of the job# handler is the function which handles the job@submit: (name, params) -># name is the name of the job# params is the data that should be sent
After that, you should register your driver under chosen name:
Que.registerDriver 'someDriver', SomeDriver
Users of your driver will be able to connect to it using URL like someDriver://localhost:port/.
Run all the needed backends and execute
mocha in Terminal.