query-swarm
Advanced tools
| language: node_js | ||
| node_js: | ||
| - "0.11" | ||
| - "0.10" | ||
| services: | ||
| - redis-server |
+4
-0
@@ -15,1 +15,5 @@ # EditorConfig is awesome: http://EditorConfig.org | ||
| indent_size = 2 | ||
| [**.yml] | ||
| indent_style = space | ||
| indent_size = 2 |
@@ -83,2 +83,3 @@ 'use strict'; | ||
| self.active = true; | ||
| return self; | ||
| }; | ||
@@ -95,2 +96,4 @@ | ||
| }); | ||
| return self; | ||
| }; | ||
@@ -103,2 +106,3 @@ | ||
| }); | ||
| return self; | ||
| }; | ||
@@ -182,2 +186,3 @@ | ||
| }); | ||
| return self; | ||
| }; | ||
@@ -184,0 +189,0 @@ |
+5
-4
| { | ||
| "name": "query-swarm", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "description": "Safely distribute query-driven tasks over a swarm of parallel functions on a single process or across multiple processes/machines.", | ||
| "keywords": "schedule, queue, task, job, worker, redis, distributed, async", | ||
| "author": "Mike Marcacci <mike.marcacci@thecontrolgroup.com>", | ||
@@ -29,3 +30,4 @@ "contributors": [ | ||
| "dependencies": { | ||
| "async": "^0.9.0" | ||
| "async": "^0.9.0", | ||
| "redis": "^0.11.0" | ||
| }, | ||
@@ -35,5 +37,4 @@ "devDependencies": { | ||
| "mocha": "^1.21.0", | ||
| "redis": "^0.11.0", | ||
| "redis-mock": "^0.3.0" | ||
| "redis": "^0.11.0" | ||
| } | ||
| } |
+38
-0
@@ -6,2 +6,40 @@ Query Swarm | ||
| tl;dr | ||
| ----- | ||
| ```js | ||
| var redis = require('redis').createClient(); | ||
| var QuerySwarm = require('../lib/QuerySwarm.js')(redis); | ||
| function query(cursor, callback) { | ||
| // you can get a starting cursor from another data source if you wish | ||
| cursor = cursor || 0; | ||
| // perform the query (you would probably connect to a database here...) | ||
| var results = [], newCursor = cursor; | ||
| while (newCursor < cursor + 100) { | ||
| results.push(newCursor); | ||
| newCursor++; | ||
| } | ||
| // return any error, the new cursor, and results | ||
| callback(null, newCursor, results); | ||
| } | ||
| function worker(task, callback) { | ||
| // do something with the task | ||
| var result = task * 2; | ||
| // return any error, and the result | ||
| callback(null, result); | ||
| } | ||
| var swarm = new QuerySwarm('myFirstSwarm', query, worker); | ||
| swarm.start(); | ||
| swarm.stop(function(){ | ||
| // this node has gracefully stopped | ||
| }); | ||
| ``` | ||
| ####Use when the following are important: | ||
@@ -8,0 +46,0 @@ - Tasks should be allowed a long time to complete |
Sorry, the diff of this file is not supported yet
-1
| console.log(10 % 5 === 0); |
20030
4.55%3
-25%539
0.56%73
108.57%2
100%8
-11.11%+ Added
+ Added