You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fully interoperable with gearman clients and workers written in other languages
cons:
lacks elegant high level abstractions for doing work. A bit more boilerplate to write
only supports 1 server connection per client/worker
Install
npm install gearman
Building
npm run build
Test
npm test
Examples
create a client, create 1 job, and handle it's completion
Gearman=require('gearman').Gearmanclient=newGearman("localhost", 4730 , {timeout:3000}) # timeout in milliseconds. # handle timeout client.on'timeout', () ->console.log'Timeout occurred'client.close()
# handle finished jobsclient.on'WORK_COMPLETE', (job) ->console.log'job completed, result:', job.payload.toString()
client.close()
# connect to the gearman serverclient.connect-># submit a job to uppercase a string with normal priority in the foregroundclient.submitJob'upper', 'Hello, World!'
create a worker, register a function, and handle jobs
Gearman=require('gearman').Gearmanworker=newGearman('127.0.0.1', 4730)
# handle jobs assigned by the serverworker.on'JOB_ASSIGN', (job) ->console.logjob.func_name+' job assigned to this worker'result=job.payload.toString().toUpperCase()
# notify the server the job is doneworker.sendWorkCompletejob.handle, result
# go back to sleep, telling the server we're ready for more workworker.preSleep()
# grab a job when the server signals one is availableworker.on'NOOP', ->worker.grabJob()
# connect to the gearman server worker.connect-># register the functions this worker is capable ofworker.addFunction'upper'# tell the server the worker is going to sleep, waiting for workworker.preSleep()