Socket
Socket
Sign inDemoInstall

gearman-coffee

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gearman-coffee

gearman bindings dun' right


Version published
Maintainers
4
Created
Source

gearman-coffee

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.

Installation

npm install gearman-coffee

Workers

Workers are created with the name and function that they perform:

worker = new Worker 'reverse', (payload, worker) ->
  return worker.error 'No payload' unless payload?
  reversed = payload.toString("utf-8").split('').reverse().join ''
  worker.complete 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'
  • done([warning]): calls error if warning passed, otherwise complete

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: 4730
  debug: false
  max_retries: 0
worker = new Worker 'unstable', (payload, worker) ->
  return worker.error() if Math.random() < 0.5
  worker.done()
, default_options

Clients

Clients are used to submit work to Gearman. By default they connect to Gearman at localhost:4730:

default_options =
  host: 'localhost'
  port: 4730
  debug: false
client = new 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.submitJob('reverse', 'kitteh')
  .on 'created', (handle) ->          # JOB_CREATED
  .on 'data', (handle, data) ->       # WORK_DATA
  .on 'warning', (handle, warning) -> # WORK_WARNING
  .on 'status', (handle, num, den) -> # WORK_STATUS
  .on 'complete', (handle, data) ->   # WORK_COMPLETE
  .on 'fail', (handle) ->             # WORK_FAIL

License

MIT

FAQs

Package last updated on 27 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc