• Stars
    star
    1,226
  • Rank 38,263 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A module for sequencing and executing tasks and dependencies in maximum concurrency

Build Status Dependency Status

Orchestrator

A module for sequencing and executing tasks and dependencies in maximum concurrency

Usage

1. Get a reference:

var Orchestrator = require('orchestrator');
var orchestrator = new Orchestrator();

2. Load it up with stuff to do:

orchestrator.add('thing1', function(){
  // do stuff
});
orchestrator.add('thing2', function(){
  // do stuff
});

3. Run the tasks:

orchestrator.start('thing1', 'thing2', function (err) {
  // all done
});

API

orchestrator.add(name[, deps][, function]);

Define a task

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.

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:

orchestrator.add('thing2', function(callback){
  // do stuff
  callback(err);
});

Return a promise:

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)

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:

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 Strings

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.

orchestrator.start('thing1', 'thing2', 'thing3', 'thing4', function (err) {
  // all done
});
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

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

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

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.

More Repositories

1

gulp-exec

exec plugin for gulp
JavaScript
160
star
2

gulp-rimraf

rimraf plugin for gulp
JavaScript
149
star
3

gulp-ignore

plugin for gulp to ignore files in the stream based on file characteristics
JavaScript
122
star
4

kubernetes-hands-on-workshop

Let's learn Docker and Kubernetes!
JavaScript
103
star
5

pretty-hrtime

process.hrtime() to words
JavaScript
66
star
6

levelup-devops-github-actions-kubernetes

Live-coding a DevOps pipeline using GitHub Actions and deploying to Kubernetes
HTML
56
star
7

git-explorer

view all DAG nodes in the .git/objects folder
TypeScript
53
star
8

docker-hands-on-workshop

C#
47
star
9

ternary-stream

A ternary stream: conditionally control the flow of stream data
JavaScript
37
star
10

sequencify

A module for sequencing tasks and dependencies
JavaScript
33
star
11

minimal-apis-aspnet

A presentation about new C# features and Minimal APIs in ASP.NET. See https://robrich.org/ for more.
HTML
31
star
12

docker-vue-and-aspnetcore

Docker Isn't All Hype; Create Robust Deployments for Vue.js and ASP.NET Core
C#
28
star
13

database-devops-with-containers

Database DevOps with Containers, the companion to https://robrich.org/slides/database-devops-with-containers/#/
HTML
25
star
14

gulp-match

Does a vinyl file match a condition?
JavaScript
23
star
15

product-catalog

Reference architecture microservice API in TypeScript, Node.js, Vue.js and MemSQL
TypeScript
20
star
16

https-aspnet-core-docker-deep-dive

Demos for https://robrich.org/slides/https-aspnet-core-docker-deep-dive/#/
C#
16
star
17

gaining-confidence-cypress-tests

The code for Gaining Confidence with Cypress Tests at https://robrich.org/slides/gaining-confidence-cypress-tests/#/
TypeScript
16
star
18

create-robust-deployments-for-spa-and-api

Companion code to "Create Robust Deployments for your SPA and API", https://robrich.org/slides/create-robust-deployments-for-spa-and-api/#/
Vue
14
star
19

database-devops-pipeline

A Database DevOps Pipeline, the companion code to https://robrich.org/slides/database-devops-pipeline/
C#
14
star
20

javascript-testing-presentation

JavaScript Testing in Node, the Browser, and CI
JavaScript
13
star
21

at-the-helm-of-kubernetes

The code for the talk at https://robrich.org/slides/at-the-helm-of-kubernetes/
HTML
12
star
22

docker-in-windows-containers

C#
8
star
23

net-testing-xunit-moq

.NET Testing Best Practices
C#
7
star
24

vue-and-typescript-like-peanut-butter-and-jelly

The companion code to the talk https://robrich.org/slides/vue-and-typescript-like-peanut-butter-and-jelly/#/
Vue
7
star
25

es6-the-language-and-the-tools-workshop

Introduction to ES6: the language and the tools, a workshop
CSS
6
star
26

web-test-all-the-things

The code for https://robrich.org/slides/web-test-all-the-things/
TypeScript
6
star
27

kubernetes-test-drive

HTML
5
star
28

ConferenceScheduler

C#
5
star
29

DevOps-Pipeline-for-.NET-Apps-and-Databases-Workshop

4
star
30

iodist

An io.js version manager for the windows folks out there.
JavaScript
3
star
31

Asynchrony_in_JavaScript

JavaScript
3
star
32

litedb-and-docker

This is a demo of using LiteDB with Docker.
C#
3
star
33

async-python

The code samples from the talk at https://robrich.org/slides/async-python/
Python
3
star
34

your-technology-your-way

C#
3
star
35

aspnet-dos-and-donts-for-highly-maintainable-code

JavaScript
2
star
36

TestingInNetCore

C#
2
star
37

AzureScheduler

A web app / web job for starting and stopping Azure resources via the Azure SDK
C#
2
star
38

gulp_node_example

An example gulpfile for Node projects
JavaScript
2
star
39

execify

A module for shimmimg between execution modes: streams, promises, and callbacks
JavaScript
2
star
40

great-net-microservices

This is the companion code to [Building Great .NET Microservices](https://robrich.org/slides/great-net-microservices/).
C#
2
star
41

LoggingSample

A sample of logging client- and server-side errors to the database and to email in .NET
C#
2
star
42

BetaSigmaPhi

C#
2
star
43

jupyter_getting_started

Jupyter demos showing various use-cases
Jupyter Notebook
2
star
44

FluentValidationPlayground

JavaScript
1
star
45

mocking-typescript

The code samples for the talk [Mocking in TypeScript](https://robrich.org/slides/mocking-typescript/)
TypeScript
1
star
46

githubactionsplayground

HTML
1
star
47

WelcomeToNode

CSS
1
star
48

levelup-devops-github-actions-azure-functions

Live-coding a DevOps pipeline using GitHub Actions deploying to Azure Functions consumption
C#
1
star
49

MapD

C#
1
star
50

azure-devops-aks

Level-up Your DevOps with Azure and Kubernetes
HTML
1
star
51

robrich

About Rob Richardson | rob rich
1
star
52

handlebars-sample

An example of using Handlebars in both a traditional form post model and in a single page application (SPA)
JavaScript
1
star
53

gulp_dotnet_example

An example gulpfile for Microsoft .NET projects
JavaScript
1
star
54

cactus

JavaScript
1
star
55

git-scenarios

1
star
56

VersionSample

Git hash into assembly on build, read it back onto the site
JavaScript
1
star
57

santas-helper

Team hack for HolidayJS 2015
JavaScript
1
star
58

XamarinExample

Creating Cross Platform Apps with Xamarin Studio
C#
1
star
59

browser-control-test-app

An app that compares Windows Forms browser controls on .NET Framework
C#
1
star