diff --git a/README.md b/README.md index 1976e13..a908e8a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,19 @@ Install npm install jobmanager +Usage +---- +
+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();
+
+ Examples ----
@@ -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);
 	},
@@ -29,7 +42,7 @@ 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,
@@ -37,7 +50,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(5000);
 			else job.next();
 		}, 100);
 	},