diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-16 01:59:39 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-16 02:00:31 +0100 |
commit | bd65bb67e25a79b019d745b7262b2008ce2adb15 (patch) | |
tree | 89e1b032103a63737f1a703e6a943832ef261704 /node_modules/orchestrator | |
parent | f91466595b651721690133f58ab37f977539e95b (diff) |
incrementally verify denoms
The denominations are not stored in a separate object store.
Diffstat (limited to 'node_modules/orchestrator')
-rw-r--r-- | node_modules/orchestrator/.npmignore | 20 | ||||
-rw-r--r-- | node_modules/orchestrator/LICENSE | 40 | ||||
-rw-r--r-- | node_modules/orchestrator/README.md | 572 | ||||
-rw-r--r-- | node_modules/orchestrator/index.js | 608 | ||||
-rw-r--r-- | node_modules/orchestrator/lib/runTask.js | 132 | ||||
-rw-r--r-- | node_modules/orchestrator/package.json | 29 |
6 files changed, 697 insertions, 704 deletions
diff --git a/node_modules/orchestrator/.npmignore b/node_modules/orchestrator/.npmignore index 2422e2040..094a5f358 100644 --- a/node_modules/orchestrator/.npmignore +++ b/node_modules/orchestrator/.npmignore @@ -1,10 +1,10 @@ -.DS_Store -*.log -node_modules -build -*.node -components -*.orig -.idea -test -.travis.yml +.DS_Store
+*.log
+node_modules
+build
+*.node
+components
+*.orig
+.idea
+test
+.travis.yml
diff --git a/node_modules/orchestrator/LICENSE b/node_modules/orchestrator/LICENSE index 3d20afd94..b7346abd6 100644 --- a/node_modules/orchestrator/LICENSE +++ b/node_modules/orchestrator/LICENSE @@ -1,20 +1,20 @@ -Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.com/) - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.com/)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/orchestrator/README.md b/node_modules/orchestrator/README.md index 3d3fee45c..d87844cf4 100644 --- a/node_modules/orchestrator/README.md +++ b/node_modules/orchestrator/README.md @@ -1,286 +1,286 @@ -[](https://travis-ci.org/orchestrator/orchestrator) -[](https://david-dm.org/orchestrator/orchestrator) - -Orchestrator -============ - -A module for sequencing and executing tasks and dependencies in maximum concurrency - -Usage ------ - -### 1. Get a reference: - -```javascript -var Orchestrator = require('orchestrator'); -var orchestrator = new Orchestrator(); -``` - -### 2. Load it up with stuff to do: - -```javascript -orchestrator.add('thing1', function(){ - // do stuff -}); -orchestrator.add('thing2', function(){ - // do stuff -}); -``` - -### 3. Run the tasks: - -```javascript -orchestrator.start('thing1', 'thing2', function (err) { - // all done -}); -``` - -API ---- - -### orchestrator.add(name[, deps][, function]); - -Define a task - -```javascript -orchestrator.add('thing1', function(){ - // do stuff -}); -``` - -#### name -Type: `String` - -The name of the task. - -#### deps -Type: `Array` - -An array of task names to be executed and completed before your task will run. - -```javascript -orchestrator.add('mytask', ['array', 'of', 'task', 'names'], function() { - // Do stuff -}); -``` - -**Note:** Are your tasks running before the dependencies are complete? Make sure your dependency tasks -are correctly using the async run hints: take in a callback or return a promise or event stream. - -#### fn -Type: `function` - -The function that performs the task's operations. For asynchronous tasks, you need to provide a hint when the task is complete: - -- Take in a callback -- Return a stream or a promise - -#### examples: - -**Accept a callback:** - -```javascript -orchestrator.add('thing2', function(callback){ - // do stuff - callback(err); -}); -``` - -**Return a promise:** - -```javascript -var Q = require('q'); - -orchestrator.add('thing3', function(){ - var deferred = Q.defer(); - - // do async stuff - setTimeout(function () { - deferred.resolve(); - }, 1); - - return deferred.promise; -}); -``` - -**Return a stream:** (task is marked complete when stream ends) - -```javascript -var map = require('map-stream'); - -orchestrator.add('thing4', function(){ - var stream = map(function (args, cb) { - cb(null, args); - }); - // do stream stuff - return stream; -}); -``` - -**Note:** By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. -If you want to create a series where tasks run in a particular order, you need to do two things: - -- give it a hint to tell it when the task is done, -- and give it a hint that a task depends on completion of another. - -For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order: - -1. In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're -done or return a promise or stream that the engine should wait to resolve or end respectively. - -2. In task "two" you add a hint telling the engine that it depends on completion of the first task. - -So this example would look like this: - -```javascript -var Orchestrator = require('orchestrator'); -var orchestrator = new Orchestrator(); - -// takes in a callback so the engine knows when it'll be done -orchestrator.add('one', function (cb) { - // do stuff -- async or otherwise - cb(err); // if err is not null or undefined, the orchestration will stop, and note that it failed -}); - -// identifies a dependent task must be complete before this one begins -orchestrator.add('two', ['one'], function () { - // task 'one' is done now -}); - -orchestrator.start('one', 'two'); -``` - -### orchestrator.hasTask(name); - -Have you defined a task with this name? - -#### name -Type: `String` - -The task name to query - -### orchestrator.start(tasks...[, cb]); - -Start running the tasks - -#### tasks -Type: `String` or `Array` of `String`s - -Tasks to be executed. You may pass any number of tasks as individual arguments. - -#### cb -Type: `function`: `function (err) {` - -Callback to call after run completed. - -Passes single argument: `err`: did the orchestration succeed? - -**Note:** Tasks run concurrently and therefore may not complete in order. -**Note:** Orchestrator uses `sequencify` to resolve dependencies before running, and therefore may not start in order. -Listen to orchestration events to watch task running. - -```javascript -orchestrator.start('thing1', 'thing2', 'thing3', 'thing4', function (err) { - // all done -}); -``` -```javascript -orchestrator.start(['thing1','thing2'], ['thing3','thing4']); -``` - -**FRAGILE:** Orchestrator catches exceptions on sync runs to pass to your callback -but doesn't hook to process.uncaughtException so it can't pass those exceptions -to your callback - -**FRAGILE:** Orchestrator will ensure each task and each dependency is run once during an orchestration run -even if you specify it to run more than once. (e.g. `orchestrator.start('thing1', 'thing1')` -will only run 'thing1' once.) If you need it to run a task multiple times, wait for -the orchestration to end (start's callback) then call start again. -(e.g. `orchestrator.start('thing1', function () {orchestrator.start('thing1');})`.) -Alternatively create a second orchestrator instance. - -### orchestrator.stop() - -Stop an orchestration run currently in process - -**Note:** It will call the `start()` callback with an `err` noting the orchestration was aborted - -### orchestrator.on(event, cb); - -Listen to orchestrator internals - -#### event -Type: `String` - -Event name to listen to: -- start: from start() method, shows you the task sequence -- stop: from stop() method, the queue finished successfully -- err: from stop() method, the queue was aborted due to a task error -- task_start: from _runTask() method, task was started -- task_stop: from _runTask() method, task completed successfully -- task_err: from _runTask() method, task errored -- task_not_found: from start() method, you're trying to start a task that doesn't exist -- task_recursion: from start() method, there are recursive dependencies in your task list - -#### cb -Type: `function`: `function (e) {` - -Passes single argument: `e`: event details - -```javascript -orchestrator.on('task_start', function (e) { - // e.message is the log message - // e.task is the task name if the message applies to a task else `undefined` - // e.err is the error if event is 'err' else `undefined` -}); -// for task_end and task_err: -orchestrator.on('task_stop', function (e) { - // e is the same object from task_start - // e.message is updated to show how the task ended - // e.duration is the task run duration (in seconds) -}); -``` - -**Note:** fires either *stop or *err but not both. - -### orchestrator.onAll(cb); - -Listen to all orchestrator events from one callback - -#### cb -Type: `function`: `function (e) {` - -Passes single argument: `e`: event details - -```javascript -orchestrator.onAll(function (e) { - // e is the original event args - // e.src is event name -}); -``` - -LICENSE -------- - -(MIT License) - -Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.com/) - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +[](https://travis-ci.org/robrich/orchestrator)
+[](https://david-dm.org/robrich/orchestrator)
+
+Orchestrator
+============
+
+A module for sequencing and executing tasks and dependencies in maximum concurrency
+
+Usage
+-----
+
+### 1. Get a reference:
+
+```javascript
+var Orchestrator = require('orchestrator');
+var orchestrator = new Orchestrator();
+```
+
+### 2. Load it up with stuff to do:
+
+```javascript
+orchestrator.add('thing1', function(){
+ // do stuff
+});
+orchestrator.add('thing2', function(){
+ // do stuff
+});
+```
+
+### 3. Run the tasks:
+
+```javascript
+orchestrator.start('thing1', 'thing2', function (err) {
+ // all done
+});
+```
+
+API
+---
+
+### orchestrator.add(name[, deps][, function]);
+
+Define a task
+
+```javascript
+orchestrator.add('thing1', function(){
+ // do stuff
+});
+```
+
+#### name
+Type: `String`
+
+The name of the task.
+
+#### deps
+Type: `Array`
+
+An array of task names to be executed and completed before your task will run.
+
+```javascript
+orchestrator.add('mytask', ['array', 'of', 'task', 'names'], function() {
+ // Do stuff
+});
+```
+
+**Note:** Are your tasks running before the dependencies are complete? Make sure your dependency tasks
+are correctly using the async run hints: take in a callback or return a promise or event stream.
+
+#### fn
+Type: `function`
+
+The function that performs the task's operations. For asynchronous tasks, you need to provide a hint when the task is complete:
+
+- Take in a callback
+- Return a stream or a promise
+
+#### examples:
+
+**Accept a callback:**
+
+```javascript
+orchestrator.add('thing2', function(callback){
+ // do stuff
+ callback(err);
+});
+```
+
+**Return a promise:**
+
+```javascript
+var Q = require('q');
+
+orchestrator.add('thing3', function(){
+ var deferred = Q.defer();
+
+ // do async stuff
+ setTimeout(function () {
+ deferred.resolve();
+ }, 1);
+
+ return deferred.promise;
+});
+```
+
+**Return a stream:** (task is marked complete when stream ends)
+
+```javascript
+var map = require('map-stream');
+
+orchestrator.add('thing4', function(){
+ var stream = map(function (args, cb) {
+ cb(null, args);
+ });
+ // do stream stuff
+ return stream;
+});
+```
+
+**Note:** By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing.
+If you want to create a series where tasks run in a particular order, you need to do two things:
+
+- give it a hint to tell it when the task is done,
+- and give it a hint that a task depends on completion of another.
+
+For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:
+
+1. In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're
+done or return a promise or stream that the engine should wait to resolve or end respectively.
+
+2. In task "two" you add a hint telling the engine that it depends on completion of the first task.
+
+So this example would look like this:
+
+```javascript
+var Orchestrator = require('orchestrator');
+var orchestrator = new Orchestrator();
+
+// takes in a callback so the engine knows when it'll be done
+orchestrator.add('one', function (cb) {
+ // do stuff -- async or otherwise
+ cb(err); // if err is not null or undefined, the orchestration will stop, and note that it failed
+});
+
+// identifies a dependent task must be complete before this one begins
+orchestrator.add('two', ['one'], function () {
+ // task 'one' is done now
+});
+
+orchestrator.start('one', 'two');
+```
+
+### orchestrator.hasTask(name);
+
+Have you defined a task with this name?
+
+#### name
+Type: `String`
+
+The task name to query
+
+### orchestrator.start(tasks...[, cb]);
+
+Start running the tasks
+
+#### tasks
+Type: `String` or `Array` of `String`s
+
+Tasks to be executed. You may pass any number of tasks as individual arguments.
+
+#### cb
+Type: `function`: `function (err) {`
+
+Callback to call after run completed.
+
+Passes single argument: `err`: did the orchestration succeed?
+
+**Note:** Tasks run concurrently and therefore may not complete in order.
+**Note:** Orchestrator uses `sequencify` to resolve dependencies before running, and therefore may not start in order.
+Listen to orchestration events to watch task running.
+
+```javascript
+orchestrator.start('thing1', 'thing2', 'thing3', 'thing4', function (err) {
+ // all done
+});
+```
+```javascript
+orchestrator.start(['thing1','thing2'], ['thing3','thing4']);
+```
+
+**FRAGILE:** Orchestrator catches exceptions on sync runs to pass to your callback
+but doesn't hook to process.uncaughtException so it can't pass those exceptions
+to your callback
+
+**FRAGILE:** Orchestrator will ensure each task and each dependency is run once during an orchestration run
+even if you specify it to run more than once. (e.g. `orchestrator.start('thing1', 'thing1')`
+will only run 'thing1' once.) If you need it to run a task multiple times, wait for
+the orchestration to end (start's callback) then call start again.
+(e.g. `orchestrator.start('thing1', function () {orchestrator.start('thing1');})`.)
+Alternatively create a second orchestrator instance.
+
+### orchestrator.stop()
+
+Stop an orchestration run currently in process
+
+**Note:** It will call the `start()` callback with an `err` noting the orchestration was aborted
+
+### orchestrator.on(event, cb);
+
+Listen to orchestrator internals
+
+#### event
+Type: `String`
+
+Event name to listen to:
+- start: from start() method, shows you the task sequence
+- stop: from stop() method, the queue finished successfully
+- err: from stop() method, the queue was aborted due to a task error
+- task_start: from _runTask() method, task was started
+- task_stop: from _runTask() method, task completed successfully
+- task_err: from _runTask() method, task errored
+- task_not_found: from start() method, you're trying to start a task that doesn't exist
+- task_recursion: from start() method, there are recursive dependencies in your task list
+
+#### cb
+Type: `function`: `function (e) {`
+
+Passes single argument: `e`: event details
+
+```javascript
+orchestrator.on('task_start', function (e) {
+ // e.message is the log message
+ // e.task is the task name if the message applies to a task else `undefined`
+ // e.err is the error if event is 'err' else `undefined`
+});
+// for task_end and task_err:
+orchestrator.on('task_stop', function (e) {
+ // e is the same object from task_start
+ // e.message is updated to show how the task ended
+ // e.duration is the task run duration (in seconds)
+});
+```
+
+**Note:** fires either *stop or *err but not both.
+
+### orchestrator.onAll(cb);
+
+Listen to all orchestrator events from one callback
+
+#### cb
+Type: `function`: `function (e) {`
+
+Passes single argument: `e`: event details
+
+```javascript
+orchestrator.onAll(function (e) {
+ // e is the original event args
+ // e.src is event name
+});
+```
+
+LICENSE
+-------
+
+(MIT License)
+
+Copyright (c) 2013-2015 [Richardson & Sons, LLC](http://richardsonandsons.com/)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/orchestrator/index.js b/node_modules/orchestrator/index.js index b13d9927d..89bc7956b 100644 --- a/node_modules/orchestrator/index.js +++ b/node_modules/orchestrator/index.js @@ -1,304 +1,304 @@ -/*jshint node:true */ - -"use strict"; - -var util = require('util'); -var events = require('events'); -var EventEmitter = events.EventEmitter; -var runTask = require('./lib/runTask'); - -var Orchestrator = function () { - EventEmitter.call(this); - this.doneCallback = undefined; // call this when all tasks in the queue are done - this.seq = []; // the order to run the tasks - this.tasks = {}; // task objects: name, dep (list of names of dependencies), fn (the task to run) - this.isRunning = false; // is the orchestrator running tasks? .start() to start, .stop() to stop -}; -util.inherits(Orchestrator, EventEmitter); - - Orchestrator.prototype.reset = function () { - if (this.isRunning) { - this.stop(null); - } - this.tasks = {}; - this.seq = []; - this.isRunning = false; - this.doneCallback = undefined; - return this; - }; - Orchestrator.prototype.add = function (name, dep, fn) { - if (!fn && typeof dep === 'function') { - fn = dep; - dep = undefined; - } - dep = dep || []; - fn = fn || function () {}; // no-op - if (!name) { - throw new Error('Task requires a name'); - } - // validate name is a string, dep is an array of strings, and fn is a function - if (typeof name !== 'string') { - throw new Error('Task requires a name that is a string'); - } - if (typeof fn !== 'function') { - throw new Error('Task '+name+' requires a function that is a function'); - } - if (!Array.isArray(dep)) { - throw new Error('Task '+name+' can\'t support dependencies that is not an array of strings'); - } - dep.forEach(function (item) { - if (typeof item !== 'string') { - throw new Error('Task '+name+' dependency '+item+' is not a string'); - } - }); - this.tasks[name] = { - fn: fn, - dep: dep, - name: name - }; - return this; - }; - Orchestrator.prototype.task = function (name, dep, fn) { - if (dep || fn) { - // alias for add, return nothing rather than this - this.add(name, dep, fn); - } else { - return this.tasks[name]; - } - }; - Orchestrator.prototype.hasTask = function (name) { - return !!this.tasks[name]; - }; - // tasks and optionally a callback - Orchestrator.prototype.start = function() { - var args, arg, names = [], lastTask, i, seq = []; - args = Array.prototype.slice.call(arguments, 0); - if (args.length) { - lastTask = args[args.length-1]; - if (typeof lastTask === 'function') { - this.doneCallback = lastTask; - args.pop(); - } - for (i = 0; i < args.length; i++) { - arg = args[i]; - if (typeof arg === 'string') { - names.push(arg); - } else if (Array.isArray(arg)) { - names = names.concat(arg); // FRAGILE: ASSUME: it's an array of strings - } else { - throw new Error('pass strings or arrays of strings'); - } - } - } - if (this.isRunning) { - // reset specified tasks (and dependencies) as not run - this._resetSpecificTasks(names); - } else { - // reset all tasks as not run - this._resetAllTasks(); - } - if (this.isRunning) { - // if you call start() again while a previous run is still in play - // prepend the new tasks to the existing task queue - names = names.concat(this.seq); - } - if (names.length < 1) { - // run all tasks - for (i in this.tasks) { - if (this.tasks.hasOwnProperty(i)) { - names.push(this.tasks[i].name); - } - } - } - seq = []; - try { - this.sequence(this.tasks, names, seq, []); - } catch (err) { - // Is this a known error? - if (err) { - if (err.missingTask) { - this.emit('task_not_found', {message: err.message, task:err.missingTask, err: err}); - } - if (err.recursiveTasks) { - this.emit('task_recursion', {message: err.message, recursiveTasks:err.recursiveTasks, err: err}); - } - } - this.stop(err); - return this; - } - this.seq = seq; - this.emit('start', {message:'seq: '+this.seq.join(',')}); - if (!this.isRunning) { - this.isRunning = true; - } - this._runStep(); - return this; - }; - Orchestrator.prototype.stop = function (err, successfulFinish) { - this.isRunning = false; - if (err) { - this.emit('err', {message:'orchestration failed', err:err}); - } else if (successfulFinish) { - this.emit('stop', {message:'orchestration succeeded'}); - } else { - // ASSUME - err = 'orchestration aborted'; - this.emit('err', {message:'orchestration aborted', err: err}); - } - if (this.doneCallback) { - // Avoid calling it multiple times - this.doneCallback(err); - } else if (err && !this.listeners('err').length) { - // No one is listening for the error so speak louder - throw err; - } - }; - Orchestrator.prototype.sequence = require('sequencify'); - Orchestrator.prototype.allDone = function () { - var i, task, allDone = true; // nothing disputed it yet - for (i = 0; i < this.seq.length; i++) { - task = this.tasks[this.seq[i]]; - if (!task.done) { - allDone = false; - break; - } - } - return allDone; - }; - Orchestrator.prototype._resetTask = function(task) { - if (task) { - if (task.done) { - task.done = false; - } - delete task.start; - delete task.stop; - delete task.duration; - delete task.hrDuration; - delete task.args; - } - }; - Orchestrator.prototype._resetAllTasks = function() { - var task; - for (task in this.tasks) { - if (this.tasks.hasOwnProperty(task)) { - this._resetTask(this.tasks[task]); - } - } - }; - Orchestrator.prototype._resetSpecificTasks = function (names) { - var i, name, t; - - if (names && names.length) { - for (i = 0; i < names.length; i++) { - name = names[i]; - t = this.tasks[name]; - if (t) { - this._resetTask(t); - if (t.dep && t.dep.length) { - this._resetSpecificTasks(t.dep); // recurse - } - //} else { - // FRAGILE: ignore that the task doesn't exist - } - } - } - }; - Orchestrator.prototype._runStep = function () { - var i, task; - if (!this.isRunning) { - return; // user aborted, ASSUME: stop called previously - } - for (i = 0; i < this.seq.length; i++) { - task = this.tasks[this.seq[i]]; - if (!task.done && !task.running && this._readyToRunTask(task)) { - this._runTask(task); - } - if (!this.isRunning) { - return; // task failed or user aborted, ASSUME: stop called previously - } - } - if (this.allDone()) { - this.stop(null, true); - } - }; - Orchestrator.prototype._readyToRunTask = function (task) { - var ready = true, // no one disproved it yet - i, name, t; - if (task.dep.length) { - for (i = 0; i < task.dep.length; i++) { - name = task.dep[i]; - t = this.tasks[name]; - if (!t) { - // FRAGILE: this should never happen - this.stop("can't run "+task.name+" because it depends on "+name+" which doesn't exist"); - ready = false; - break; - } - if (!t.done) { - ready = false; - break; - } - } - } - return ready; - }; - Orchestrator.prototype._stopTask = function (task, meta) { - task.duration = meta.duration; - task.hrDuration = meta.hrDuration; - task.running = false; - task.done = true; - }; - Orchestrator.prototype._emitTaskDone = function (task, message, err) { - if (!task.args) { - task.args = {task:task.name}; - } - task.args.duration = task.duration; - task.args.hrDuration = task.hrDuration; - task.args.message = task.name+' '+message; - var evt = 'stop'; - if (err) { - task.args.err = err; - evt = 'err'; - } - // 'task_stop' or 'task_err' - this.emit('task_'+evt, task.args); - }; - Orchestrator.prototype._runTask = function (task) { - var that = this; - - task.args = {task:task.name, message:task.name+' started'}; - this.emit('task_start', task.args); - task.running = true; - - runTask(task.fn.bind(this), function (err, meta) { - that._stopTask.call(that, task, meta); - that._emitTaskDone.call(that, task, meta.runMethod, err); - if (err) { - return that.stop.call(that, err); - } - that._runStep.call(that); - }); - }; - -// FRAGILE: ASSUME: this list is an exhaustive list of events emitted -var events = ['start','stop','err','task_start','task_stop','task_err','task_not_found','task_recursion']; - -var listenToEvent = function (target, event, callback) { - target.on(event, function (e) { - e.src = event; - callback(e); - }); -}; - - Orchestrator.prototype.onAll = function (callback) { - var i; - if (typeof callback !== 'function') { - throw new Error('No callback specified'); - } - - for (i = 0; i < events.length; i++) { - listenToEvent(this, events[i], callback); - } - }; - -module.exports = Orchestrator; +/*jshint node:true */
+
+"use strict";
+
+var util = require('util');
+var events = require('events');
+var EventEmitter = events.EventEmitter;
+var runTask = require('./lib/runTask');
+
+var Orchestrator = function () {
+ EventEmitter.call(this);
+ this.doneCallback = undefined; // call this when all tasks in the queue are done
+ this.seq = []; // the order to run the tasks
+ this.tasks = {}; // task objects: name, dep (list of names of dependencies), fn (the task to run)
+ this.isRunning = false; // is the orchestrator running tasks? .start() to start, .stop() to stop
+};
+util.inherits(Orchestrator, EventEmitter);
+
+ Orchestrator.prototype.reset = function () {
+ if (this.isRunning) {
+ this.stop(null);
+ }
+ this.tasks = {};
+ this.seq = [];
+ this.isRunning = false;
+ this.doneCallback = undefined;
+ return this;
+ };
+ Orchestrator.prototype.add = function (name, dep, fn) {
+ if (!fn && typeof dep === 'function') {
+ fn = dep;
+ dep = undefined;
+ }
+ dep = dep || [];
+ fn = fn || function () {}; // no-op
+ if (!name) {
+ throw new Error('Task requires a name');
+ }
+ // validate name is a string, dep is an array of strings, and fn is a function
+ if (typeof name !== 'string') {
+ throw new Error('Task requires a name that is a string');
+ }
+ if (typeof fn !== 'function') {
+ throw new Error('Task '+name+' requires a function that is a function');
+ }
+ if (!Array.isArray(dep)) {
+ throw new Error('Task '+name+' can\'t support dependencies that is not an array of strings');
+ }
+ dep.forEach(function (item) {
+ if (typeof item !== 'string') {
+ throw new Error('Task '+name+' dependency '+item+' is not a string');
+ }
+ });
+ this.tasks[name] = {
+ fn: fn,
+ dep: dep,
+ name: name
+ };
+ return this;
+ };
+ Orchestrator.prototype.task = function (name, dep, fn) {
+ if (dep || fn) {
+ // alias for add, return nothing rather than this
+ this.add(name, dep, fn);
+ } else {
+ return this.tasks[name];
+ }
+ };
+ Orchestrator.prototype.hasTask = function (name) {
+ return !!this.tasks[name];
+ };
+ // tasks and optionally a callback
+ Orchestrator.prototype.start = function() {
+ var args, arg, names = [], lastTask, i, seq = [];
+ args = Array.prototype.slice.call(arguments, 0);
+ if (args.length) {
+ lastTask = args[args.length-1];
+ if (typeof lastTask === 'function') {
+ this.doneCallback = lastTask;
+ args.pop();
+ }
+ for (i = 0; i < args.length; i++) {
+ arg = args[i];
+ if (typeof arg === 'string') {
+ names.push(arg);
+ } else if (Array.isArray(arg)) {
+ names = names.concat(arg); // FRAGILE: ASSUME: it's an array of strings
+ } else {
+ throw new Error('pass strings or arrays of strings');
+ }
+ }
+ }
+ if (this.isRunning) {
+ // reset specified tasks (and dependencies) as not run
+ this._resetSpecificTasks(names);
+ } else {
+ // reset all tasks as not run
+ this._resetAllTasks();
+ }
+ if (this.isRunning) {
+ // if you call start() again while a previous run is still in play
+ // prepend the new tasks to the existing task queue
+ names = names.concat(this.seq);
+ }
+ if (names.length < 1) {
+ // run all tasks
+ for (i in this.tasks) {
+ if (this.tasks.hasOwnProperty(i)) {
+ names.push(this.tasks[i].name);
+ }
+ }
+ }
+ seq = [];
+ try {
+ this.sequence(this.tasks, names, seq, []);
+ } catch (err) {
+ // Is this a known error?
+ if (err) {
+ if (err.missingTask) {
+ this.emit('task_not_found', {message: err.message, task:err.missingTask, err: err});
+ }
+ if (err.recursiveTasks) {
+ this.emit('task_recursion', {message: err.message, recursiveTasks:err.recursiveTasks, err: err});
+ }
+ }
+ this.stop(err);
+ return this;
+ }
+ this.seq = seq;
+ this.emit('start', {message:'seq: '+this.seq.join(',')});
+ if (!this.isRunning) {
+ this.isRunning = true;
+ }
+ this._runStep();
+ return this;
+ };
+ Orchestrator.prototype.stop = function (err, successfulFinish) {
+ this.isRunning = false;
+ if (err) {
+ this.emit('err', {message:'orchestration failed', err:err});
+ } else if (successfulFinish) {
+ this.emit('stop', {message:'orchestration succeeded'});
+ } else {
+ // ASSUME
+ err = 'orchestration aborted';
+ this.emit('err', {message:'orchestration aborted', err: err});
+ }
+ if (this.doneCallback) {
+ // Avoid calling it multiple times
+ this.doneCallback(err);
+ } else if (err && !this.listeners('err').length) {
+ // No one is listening for the error so speak louder
+ throw err;
+ }
+ };
+ Orchestrator.prototype.sequence = require('sequencify');
+ Orchestrator.prototype.allDone = function () {
+ var i, task, allDone = true; // nothing disputed it yet
+ for (i = 0; i < this.seq.length; i++) {
+ task = this.tasks[this.seq[i]];
+ if (!task.done) {
+ allDone = false;
+ break;
+ }
+ }
+ return allDone;
+ };
+ Orchestrator.prototype._resetTask = function(task) {
+ if (task) {
+ if (task.done) {
+ task.done = false;
+ }
+ delete task.start;
+ delete task.stop;
+ delete task.duration;
+ delete task.hrDuration;
+ delete task.args;
+ }
+ };
+ Orchestrator.prototype._resetAllTasks = function() {
+ var task;
+ for (task in this.tasks) {
+ if (this.tasks.hasOwnProperty(task)) {
+ this._resetTask(this.tasks[task]);
+ }
+ }
+ };
+ Orchestrator.prototype._resetSpecificTasks = function (names) {
+ var i, name, t;
+
+ if (names && names.length) {
+ for (i = 0; i < names.length; i++) {
+ name = names[i];
+ t = this.tasks[name];
+ if (t) {
+ this._resetTask(t);
+ if (t.dep && t.dep.length) {
+ this._resetSpecificTasks(t.dep); // recurse
+ }
+ //} else {
+ // FRAGILE: ignore that the task doesn't exist
+ }
+ }
+ }
+ };
+ Orchestrator.prototype._runStep = function () {
+ var i, task;
+ if (!this.isRunning) {
+ return; // user aborted, ASSUME: stop called previously
+ }
+ for (i = 0; i < this.seq.length; i++) {
+ task = this.tasks[this.seq[i]];
+ if (!task.done && !task.running && this._readyToRunTask(task)) {
+ this._runTask(task);
+ }
+ if (!this.isRunning) {
+ return; // task failed or user aborted, ASSUME: stop called previously
+ }
+ }
+ if (this.allDone()) {
+ this.stop(null, true);
+ }
+ };
+ Orchestrator.prototype._readyToRunTask = function (task) {
+ var ready = true, // no one disproved it yet
+ i, name, t;
+ if (task.dep.length) {
+ for (i = 0; i < task.dep.length; i++) {
+ name = task.dep[i];
+ t = this.tasks[name];
+ if (!t) {
+ // FRAGILE: this should never happen
+ this.stop("can't run "+task.name+" because it depends on "+name+" which doesn't exist");
+ ready = false;
+ break;
+ }
+ if (!t.done) {
+ ready = false;
+ break;
+ }
+ }
+ }
+ return ready;
+ };
+ Orchestrator.prototype._stopTask = function (task, meta) {
+ task.duration = meta.duration;
+ task.hrDuration = meta.hrDuration;
+ task.running = false;
+ task.done = true;
+ };
+ Orchestrator.prototype._emitTaskDone = function (task, message, err) {
+ if (!task.args) {
+ task.args = {task:task.name};
+ }
+ task.args.duration = task.duration;
+ task.args.hrDuration = task.hrDuration;
+ task.args.message = task.name+' '+message;
+ var evt = 'stop';
+ if (err) {
+ task.args.err = err;
+ evt = 'err';
+ }
+ // 'task_stop' or 'task_err'
+ this.emit('task_'+evt, task.args);
+ };
+ Orchestrator.prototype._runTask = function (task) {
+ var that = this;
+
+ task.args = {task:task.name, message:task.name+' started'};
+ this.emit('task_start', task.args);
+ task.running = true;
+
+ runTask(task.fn.bind(this), function (err, meta) {
+ that._stopTask.call(that, task, meta);
+ that._emitTaskDone.call(that, task, meta.runMethod, err);
+ if (err) {
+ return that.stop.call(that, err);
+ }
+ that._runStep.call(that);
+ });
+ };
+
+// FRAGILE: ASSUME: this list is an exhaustive list of events emitted
+var events = ['start','stop','err','task_start','task_stop','task_err','task_not_found','task_recursion'];
+
+var listenToEvent = function (target, event, callback) {
+ target.on(event, function (e) {
+ e.src = event;
+ callback(e);
+ });
+};
+
+ Orchestrator.prototype.onAll = function (callback) {
+ var i;
+ if (typeof callback !== 'function') {
+ throw new Error('No callback specified');
+ }
+
+ for (i = 0; i < events.length; i++) {
+ listenToEvent(this, events[i], callback);
+ }
+ };
+
+module.exports = Orchestrator;
diff --git a/node_modules/orchestrator/lib/runTask.js b/node_modules/orchestrator/lib/runTask.js index 97dae22cb..41b28778b 100644 --- a/node_modules/orchestrator/lib/runTask.js +++ b/node_modules/orchestrator/lib/runTask.js @@ -1,66 +1,66 @@ -/*jshint node:true */ - -"use strict"; - -var eos = require('end-of-stream'); -var consume = require('stream-consume'); - -module.exports = function (task, done) { - var that = this, finish, cb, isDone = false, start, r; - - finish = function (err, runMethod) { - var hrDuration = process.hrtime(start); - - if (isDone && !err) { - err = new Error('task completion callback called too many times'); - } - isDone = true; - - var duration = hrDuration[0] + (hrDuration[1] / 1e9); // seconds - - done.call(that, err, { - duration: duration, // seconds - hrDuration: hrDuration, // [seconds,nanoseconds] - runMethod: runMethod - }); - }; - - cb = function (err) { - finish(err, 'callback'); - }; - - try { - start = process.hrtime(); - r = task(cb); - } catch (err) { - return finish(err, 'catch'); - } - - if (r && typeof r.then === 'function') { - // wait for promise to resolve - // FRAGILE: ASSUME: Promises/A+, see http://promises-aplus.github.io/promises-spec/ - r.then(function () { - finish(null, 'promise'); - }, function(err) { - finish(err, 'promise'); - }); - - } else if (r && typeof r.pipe === 'function') { - // wait for stream to end - - eos(r, { error: true, readable: r.readable, writable: r.writable && !r.readable }, function(err){ - finish(err, 'stream'); - }); - - // Ensure that the stream completes - consume(r); - - } else if (task.length === 0) { - // synchronous, function took in args.length parameters, and the callback was extra - finish(null, 'sync'); - - //} else { - // FRAGILE: ASSUME: callback - - } -}; +/*jshint node:true */
+
+"use strict";
+
+var eos = require('end-of-stream');
+var consume = require('stream-consume');
+
+module.exports = function (task, done) {
+ var that = this, finish, cb, isDone = false, start, r;
+
+ finish = function (err, runMethod) {
+ var hrDuration = process.hrtime(start);
+
+ if (isDone && !err) {
+ err = new Error('task completion callback called too many times');
+ }
+ isDone = true;
+
+ var duration = hrDuration[0] + (hrDuration[1] / 1e9); // seconds
+
+ done.call(that, err, {
+ duration: duration, // seconds
+ hrDuration: hrDuration, // [seconds,nanoseconds]
+ runMethod: runMethod
+ });
+ };
+
+ cb = function (err) {
+ finish(err, 'callback');
+ };
+
+ try {
+ start = process.hrtime();
+ r = task(cb);
+ } catch (err) {
+ return finish(err, 'catch');
+ }
+
+ if (r && typeof r.then === 'function') {
+ // wait for promise to resolve
+ // FRAGILE: ASSUME: Promises/A+, see http://promises-aplus.github.io/promises-spec/
+ r.then(function () {
+ finish(null, 'promise');
+ }, function(err) {
+ finish(err, 'promise');
+ });
+
+ } else if (r && typeof r.pipe === 'function') {
+ // wait for stream to end
+
+ eos(r, { error: true, readable: r.readable, writable: r.writable && !r.readable }, function(err){
+ finish(err, 'stream');
+ });
+
+ // Ensure that the stream completes
+ consume(r);
+
+ } else if (task.length === 0) {
+ // synchronous, function took in args.length parameters, and the callback was extra
+ finish(null, 'sync');
+
+ //} else {
+ // FRAGILE: ASSUME: callback
+
+ }
+};
diff --git a/node_modules/orchestrator/package.json b/node_modules/orchestrator/package.json index ed85b5355..7107bfd93 100644 --- a/node_modules/orchestrator/package.json +++ b/node_modules/orchestrator/package.json @@ -1,7 +1,7 @@ { "name": "orchestrator", "description": "A module for sequencing and executing tasks and dependencies in maximum concurrency", - "version": "0.3.7", + "version": "0.3.8", "homepage": "https://github.com/robrich/orchestrator", "repository": "git://github.com/robrich/orchestrator.git", "author": "Rob Richardson (http://robrich.org/)", @@ -18,25 +18,18 @@ "stream-consume": "~0.1.0" }, "devDependencies": { - "event-stream": "~3.1.5", - "gulp-jshint": "~1.6.3", - "map-stream": "~0.1.0", - "merge-stream": "~0.1.2", - "mocha": "~1.17.0", - "q": "~1.0.0", - "should": "~3.0.1", - "vinyl-fs": "~0.3.4" + "event-stream": "~3.3.4", + "gulp-uglify": "^2.0.0", + "jshint": "^2.9.4", + "map-stream": "~0.0.6", + "merge-stream": "~1.0.0", + "mocha": "~3.1.2", + "q": "~1.4.1", + "should": "~11.1.1", + "vinyl-fs": "~2.4.4" }, "scripts": { "test": "mocha" }, - "engines": { - "node": ">= 0.8" - }, - "licenses": [ - { - "type": "MIT", - "url": "http://github.com/robrich/orchestrator/raw/master/LICENSE" - } - ] + "license": "MIT" } |