gearman-coffee 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.
npm install gearman-coffee
Workers are created with the name and function that they perform:
worker = 'reverse'return workererror 'No payload' unless payload?reversed = payloadtoString"utf-8"split''reversejoin ''workercomplete reversed
The worker function itself is passed an object that contains the following convenience methods:
warning(warning): sends a 'WORK_WARNING' packet
status(num,den): sends a 'WORK_STATUS' packet
data(data): sends a 'WORK_DATA' packet
error([warning]): sends an optional 'WORK_WARNING' before 'WORK_FAIL'
complete([data]): sends an optional 'WORK_DATA' before 'WORK_COMPLETE'
errorif warning passed, otherwise
The exact meaning of these is best documented on the Gearman website itself: http://gearman.org/index.php?id=protocol.
Workers optionally take a hash of options. These options control the Gearman server connection settings as well as debug output and retry behavior:
default_options =host: 'localhost'port: 4730debug: falsemax_retries: 0worker = 'unstable'return workererror if Mathrandom < 0.5workerdonedefault_options
Clients are used to submit work to Gearman. By default they connect to Gearman at
default_options =host: 'localhost'port: 4730debug: falseclient = default_options
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:
clientsubmitJob'reverse''kitteh'on 'created' # JOB_CREATEDon 'data' # WORK_DATAon 'warning' # WORK_WARNINGon 'status' # WORK_STATUSon 'complete' # WORK_COMPLETEon 'fail' # WORK_FAIL