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.
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