gearman-node
gearman-node is an implementation of the Gearman protocol in CoffeeScript. It exposes a conventional Node library for creating Gearman workers and clients, and listening for events related to both. It aims to be a very a lightweight wrapper around the protocol itself.
Installation
npm install gearman-node
Workers
Workers are created with the name and function that they perform:
var gearman = ; var worker = 'reverse' { var reversed; if payload == null return worker; reversed = payload; return workercompletereversed;};
The worker function itself is passed an object that contains the following convenience methods:
warning(warning)
: sends a 'WORK_WARNING' packetstatus(num,den)
: sends a 'WORK_STATUS' packetdata(data)
: sends a 'WORK_DATA' packeterror([warning])
: sends an optional 'WORK_WARNING' before 'WORK_FAIL'complete([data])
: sends an optional 'WORK_DATA' before 'WORK_COMPLETE'done([warning])
: callserror
if warning passed, otherwisecomplete
The exact meaning of these is best documented on the Gearman website itself: http://gearman.org/protocol/.
Workers optionally take a hash of options. These options control the Gearman server connection settings as well as debug output and retry behavior:
var gearman = ;var default_options worker; default_options = host: 'localhost' port: 4730 debug: false max_retries: 0; worker = 'unstable' { if Math < 05 return worker; return worker;} default_options;
Clients
Clients are used to submit work to Gearman. By default they connect to Gearman at localhost:4730
:
var gearman = ;var client default_options; default_options = host: 'localhost' port: 4730 debug: false; client = default_options;
The submitJob
method of the client takes in the name of the worker and the workload you'd like to send. It returns an EventEmitter that relays Gearman server notifications:
client ; // JOB_CREATED ; // WORK_DATA ; // WORK_WARNING ; // WORK_STATUS ; // WORK_COMPLETE ; // WORK_FAIL
License
MIT