# gearman-node

> gearman bindings dun' right

Latest version **2.0.13** (published 2017-01-12) · 0 weekly downloads

## Install

```sh
npm install gearman-node
pnpm add gearman-node
yarn add gearman-node
bun add gearman-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.13 |
| Published | 2017-01-12 |
| First published | 2014-08-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.6.x |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Clever |
| Maintainers | azylman, clever, dsparks, eighnjel, kvigen, nathanleiby, rgarcia, schimmy |

## Links

- npm: https://www.npmjs.com/package/gearman-node
- Repository: https://github.com/Clever/gearman-node
- Homepage: https://github.com/Clever/gearman-node#readme
- Issues: https://github.com/Clever/gearman-node/issues
- npm.io page: https://npm.io/package/gearman-node

## Dependencies (3)

- [async](https://npm.io/package/async.md) ~0.1.22
- [underscore](https://npm.io/package/underscore.md) ~1.5.2
- [reconnect-net](https://npm.io/package/reconnect-net.md) 0.0.0

## Recent versions

- 2.0.13 (latest) — 2017-01-12
- 2.0.11 — 2015-01-26
- 2.0.10 — 2015-01-07
- 2.0.9 — 2014-10-10
- 2.0.8 — 2014-10-10
- 2.0.7 — 2014-10-02
- 2.0.6 — 2014-09-12
- 2.0.5 — 2014-09-09
- 2.0.4 — 2014-08-29

## README

# gearman-node

**gearman-node** 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-node
```

## Workers

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

```javascript
var gearman = require('gearman-node');

var worker = new gearman.Worker('reverse', function(payload, worker) {
  var reversed;
  if (payload == null) {
    return worker.error('No payload');
  }
  reversed = payload.toString("utf-8").split('').reverse().join('');
  return 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/protocol/](http://gearman.org/protocol/).

Workers optionally take a hash of options. These options control the Gearman server connection settings as well as debug output and retry behavior:

```javascript
var gearman = require('gearman-node');
var default_options, worker;

default_options = {
  host: 'localhost',
  port: 4730,
  debug: false,
  max_retries: 0
};

worker = new gearman.Worker('unstable', function(payload, worker) {
  if (Math.random() < 0.5) {
    return worker.error();
  }
  return worker.done();
}, default_options);
```

## Clients

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

```javascript
var gearman = require('gearman-node');
var client, default_options;

default_options = {
  host: 'localhost',
  port: 4730,
  debug: false
};

client = new gearman.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:

```javascript
client.submitJob('reverse', 'kitteh')
  .on('created', function(handle) { ... });           // JOB_CREATED
  .on('data', function(handle, data) { ... });        // WORK_DATA
  .on('warning', function(handle, warning) { ... });  // WORK_WARNING
  .on('status', function(handle, num, den) { ... });  // WORK_STATUS
  .on('complete', function(handle, data) { ... });    // WORK_COMPLETE
  .on('fail', function(handle) { ... });              // WORK_FAIL
```

## License

MIT

---
_Source: https://npm.io/package/gearman-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
