<commit_before>            ____                                 _   _           _
           / ___| ___  __ _ _ __ _ __ ___   __ _| \ | | ___   __| | ___
          | |  _ / _ \/ _` | '__| '_ ` _ \ / _` |  \| |/ _ \ / _` |/ _ \
          | |_| |  __/ (_| | |  | | | | | | (_| | |\  | (_) | (_| |  __/
           \____|\___|\__,_|_|  |_| |_| |_|\__,_|_| \_|\___/ \__,_|\___|


Node.js library for the Gearman distributed job system.


## Features
* fully implemented Gearman Protocol
 * TODO (RESET_ABILITIES, SET_CLIENT_ID, CAN_DO_TIMEOUT, ALL_YOURS, GRAB_JOB_UNIQ, JOB_ASSIGN_UNIQ)
* support for multiple job servers
 * load balancing strategy (`sequence` or `round-robin`)
 * recover time (when a server node is down due to maintenance or a crash, load balancer will use the recover-time as a delay before retrying the downed job server)
* support for miscellaneous string encoding supported by Node.js `Buffer` class
* careful API documentation
* rock solid tests
 * currently more than 90 test scenarios and 300 asserts
* in depth tested with gearman clients and workers written in other languages (Ruby, PHP, Java)


## Usage
See [example](https://github.com/veny/GearmaNode/tree/master/example) folder.

### Client

    var gearmanode = require('gearmanode');
    var client = gearmanode.client(); // by default expects job server on localhost:4730
    var job = client.submitJob({ name: 'reverse', payload: 'hello world!' }); // by default foreground job with normal priority
    job.on('complete', function() {
        console.log(job.toString() + " >>> " + job.response);
        client.close();
    });

### Worker

    var worker = gearmanode.worker();
    worker.addFuntion('reverse', function (job) {
        var rslt = job.payload.toString().split("").reverse().join("");
        job.workComplete(rslt);
    });

### Multiple Job Servers

```javascript
// two servers: foo.com:4731, bar.com:4732
client = gearmanode.client({ servers: [{host: 'foo.com', port: 4731}, {host: 'bar.com', port: 4732}] });
// two servers with default values: foo.com:4730, localhost:4731
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}] });
```

#### Load Balancing

+ default mode is `Sequence` which calls job server nodes in the order of nodes defined by the client initialization (next node will be used if the current one fails)
+ `RoundRobin` assigns work in round-robin order per nodes defined by the client initialization.

```javascript
// default load balancer
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}] });
// defined load balancer
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}], loadBalancing: 'RoundRobin' });
```

## Client events
* **submit** - when a job has been submited to job server, has parameter 'number of jobs waiting for response CREATED'
* **done** - when there's no submited job more waiting for state CREATED
* **connect** - when a job server connected (physical connection is lazy opened by first data sending), has parameter **job server UID**
* **disconnect** - when connection to a job server terminated (by timeout if not used or forcible by client), has parameter **job server UID**
* **close** - when Client#close() called to end the client for future use and to release all its associated resources
* **jobServerError** - whenever an associated job server encounters an error and needs to notify the client, has parameters **jobServerUid**, **code**, **message**
* **error** - when an unrecoverable error occured (e.g. illegal client's state, malformed data, socket problem, ...) or job server encounters an error and needs to notify client, has parameter **Error**
<commit_msg>markdown experiment<commit_after>            ____                                 _   _           _
           / ___| ___  __ _ _ __ _ __ ___   __ _| \ | | ___   __| | ___
          | |  _ / _ \/ _` | '__| '_ ` _ \ / _` |  \| |/ _ \ / _` |/ _ \
          | |_| |  __/ (_| | |  | | | | | | (_| | |\  | (_) | (_| |  __/
           \____|\___|\__,_|_|  |_| |_| |_|\__,_|_| \_|\___/ \__,_|\___|


Node.js library for the Gearman distributed job system.


## Features
* fully implemented Gearman Protocol
 * TODO (RESET_ABILITIES, SET_CLIENT_ID, CAN_DO_TIMEOUT, ALL_YOURS, GRAB_JOB_UNIQ, JOB_ASSIGN_UNIQ)
* support for multiple job servers
 * load balancing strategy (`sequence` or `round-robin`)
 * recover time (when a server node is down due to maintenance or a crash, load balancer will use the recover-time as a delay before retrying the downed job server)
* support for miscellaneous string encoding supported by Node.js `Buffer` class
* careful API documentation
* rock solid tests
 * currently more than 90 test scenarios and 300 asserts
* in depth tested with gearman clients and workers written in other languages (Ruby, PHP, Java)


## Usage
See [example](https://github.com/veny/GearmaNode/tree/master/example) folder.

### Client

```javascript
var gearmanode = require('gearmanode');
var client = gearmanode.client(); // by default expects job server on localhost:4730
var job = client.submitJob({ name: 'reverse', payload: 'hello world!' }); // by default foreground job with normal priority
job.on('complete', function() {
    console.log(job.toString() + " >>> " + job.response);
    client.close();
});
```

### Worker

```javascript
var worker = gearmanode.worker();
worker.addFuntion('reverse', function (job) {
    var rslt = job.payload.toString().split("").reverse().join("");
    job.workComplete(rslt);
});
```

### Multiple Job Servers

```javascript
// two servers: foo.com:4731, bar.com:4732
client = gearmanode.client({ servers: [{host: 'foo.com', port: 4731}, {host: 'bar.com', port: 4732}] });
// two servers with default values: foo.com:4730, localhost:4731
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}] });
```

#### Load Balancing

+ default mode is `Sequence` which calls job server nodes in the order of nodes defined by the client initialization (next node will be used if the current one fails)
+ `RoundRobin` assigns work in round-robin order per nodes defined by the client initialization.

```javascript
// default load balancer
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}] });
// defined load balancer
client = gearmanode.client({ servers: [{host: 'foo.com'}, {port: 4731}], loadBalancing: 'RoundRobin' });
```

## Client events
* **submit** - when a job has been submited to job server, has parameter 'number of jobs waiting for response CREATED'
* **done** - when there's no submited job more waiting for state CREATED
* **connect** - when a job server connected (physical connection is lazy opened by first data sending), has parameter **job server UID**
* **disconnect** - when connection to a job server terminated (by timeout if not used or forcible by client), has parameter **job server UID**
* **close** - when Client#close() called to end the client for future use and to release all its associated resources
* **jobServerError** - whenever an associated job server encounters an error and needs to notify the client, has parameters **jobServerUid**, **code**, **message**
* **error** - when an unrecoverable error occured (e.g. illegal client's state, malformed data, socket problem, ...) or job server encounters an error and needs to notify client, has parameter **Error**

{'fraction_non_alphanumeric': 0.13400380538189727, 'fraction_numerical': 0.012231584669747214, 'mean_word_length': 3.628301886792453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1606888', 'n_tokens_mistral': 2229, 'n_tokens_neox': 2089, 'n_words': 783}