Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
demian85 committed Sep 3, 2011
1 parent 45b5412 commit 42e2d99
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions README.md
Expand Up @@ -4,6 +4,19 @@ Install
npm install jobmanager
</pre>

Usage
----
<pre>
var JobManager = require('jobmanager').JobManager;
new JobManager({
//- (Array)input: array of items to process
//- (Number)retries: maximum number of retries before calling next()
//- (Number)max: max number of jobs to run in parallel. Default = 0 (no limit)
//- (Function)exec: Function to be called for each input item. The first argument will be the item extracted from the queue. The 2nd is an object representing the current job and has the following methods: retry(), next(). 'this' refers to the job manager instance.
//- (Function)end: Function to be called after the execution of all tasks. Also emited as 'end' event.
}).init();
</pre>

Examples
----
<pre>
Expand All @@ -19,7 +32,7 @@ new JobManager({
exec : function(item, job) {
util.log('Executing ' + item);
setTimeout(function() {
if (item%2 == 0) job.retry(0);
if (item%2 == 0) job.retry();
else job.next();
}, 100);
},
Expand All @@ -29,15 +42,15 @@ new JobManager({
}).init();

/**
* Execute a maximum of 2 tasks in parallel
* Execute a maximum of 2 tasks in parallel. Retry after 5 seconds...
*/
new JobManager({
max: 2,
input : [1,2,3,4,5,6],
exec : function(item, job) {
util.log('Executing ' + item);
setTimeout(function() {
if (item%2 == 0) job.retry(0);
if (item%2 == 0) job.retry(5000);
else job.next();
}, 100);
},
Expand Down

0 comments on commit 42e2d99

Please sign in to comment.