gearman client and worker library
##Why Another Nodejs Gearman Client? I evaluated several existing libraries on github, but they either lack features, or stability, or recent updates.
- full implementation of worker and client
- lean abstraction over raw gearman protocol
- lots of unit tests
- fully interoperable with gearman clients and workers written in other languages
- lacks elegant high level abstractions for doing work. A bit more boilerplate to write
- only supports 1 server connection per client/worker
npm install gearman-js
npm run build
Gearman = require'gearman-js'Gearmanclient = "localhost"4730 timeout: 3000 # timeout in milliseconds.# handle timeoutclienton 'timeout'consolelog 'Timeout occurred'clientclose# handle finished jobsclienton 'WORK_COMPLETE'consolelog 'job completed, result:'jobpayloadtoStringclientclose# connect to the gearman serverclientconnect -># submit a job to uppercase a string with normal priority in the foregroundclientsubmitJob 'upper''Hello, World!'
Gearman = require'gearman-js'Gearmanworker = '127.0.0.1'4730# handle jobs assigned by the serverworkeron 'JOB_ASSIGN'consolelog jobfunc_name + ' job assigned to this worker'result = jobpayloadtoStringtoUpperCase# notify the server the job is doneworkersendWorkComplete jobhandleresult# go back to sleep, telling the server we're ready for more workworkerpreSleep# grab a job when the server signals one is availableworkeron 'NOOP'->workergrabJob# connect to the gearman serverworkerconnect -># register the functions this worker is capable ofworkeraddFunction 'upper'# tell the server the worker is going to sleep, waiting for workworkerpreSleep