npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

module-orchestrator

v0.1.6

Published

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

Downloads

4

Readme

module-orchestrator

Build Status via Travis CI

Orchestrates modules based on configuration while resolving its dependencies concurrently. Applications typically web-based calls multiple services, process and aggregates the collected data from all services for every single request. Though parallel calls are addressed through libraries like async or Q, there are lot of boilerplate code that every single application has to write. This module processor aims to solve that problem while reusing async for making use of parallelism.

API

Orchestrator has to be instantiated and the input is passed as an object.


//create an object
var orch = new orchestrator(config);

//run the orchestrator	
orch.start(function(err, results) {
	// this callback function is called after orchestrator finish processing all modules
});

Create

Pass the input configuration to orchestrator with the below information

  • name - Name of the orchestrator
  • modules - Contains the collection of all modules that are to be executed
	{
	    //ModuleDescription
			"ModuleName1": { //Name of the module
				"dependency":[] //Optional. array of dependencies
			},
			"ModuleName2" : {
			  "dependency":["ModuleName1"] //Any dependency mentioned here should exists in 'modules'
			}
		}
  • pathToContext - Relative path to set the context on directory. Value of this property is prefixed before every Module.path. This is helpful when another node module wraps this orchestrator and you can set the context to any level
  • moduleResolver - Module Resolver provides a way to find the function that has to be executed.
    config.moduleResolver = function(modulename) {
        //return a function based on the module name
    }

Module orchestrator comes with a default resolver that looks up the path and do a require with pathToContext. In order to use Default resolver, path and method are needed as part of Module config

			"ModuleName3": { //Name of the module
				"path": "modules/TasksOdd", //Path to find this module. 
				"method":"Three", //Call this function after finding the module
				"dependency":[] //Optional. array of dependencies
			},
  • ctxResolver - ContextResolver provides a way to build context for a module and the constructed context from the resolver is passed on to the actual module during execution
  • onModuleComplete - Callback to be called when a module is completed with either success or failure
  • timeout - Timeout for a task to complete
  • diagnosis - When set to true, orchestrator exposes stats object on the final callback function. stats contains time taken to complete the modules and the orchestrator as well as the completion state(SUCCESS or FAILURE). Sample stats object would look like
{ 
  sampleOrchestrator: { took: '103ms' }, //time taken for the orchestrator to complete
  ModuleOne: { took: '1ms', state: 'COMPLETED_SUCCESS' }, 
  ModuleTwo: { took: '101ms', state: 'COMPLETED_SUCCESS' },
  ModReturnParam: { took: '0ms', state: 'COMPLETED_FAILURE' },
  ModuleThree: { took: '0ms', state: 'COMPLETED_SUCCESS' },
  ModuleFour: { took: '0ms', state: 'COMPLETED_SUCCESS' } 
}

Refer test/app-module-test for stats usage

Run

After start is called on orchestrator, it delegates the work to async auto. Output of every module is stored in results object and passed on to every module execution.

Sample Module declaration

Every function whose reference is mentioned in ModuleDescription should hanldle three arguments

  • cb - callback. this function accepts err as first parameter and result as second parameter
  • results - results from modules that were executed before the current module
  • ctx - context object for the current module. this object is constructed using ctxResolver
var One = function(cb, results, ctx) {
  //do application specific stuff;
      // read init values from ctx
      // read data dependency from results
      //call a service or resolve a promise here 
  //finally call the callback pass error and output of this function
  //Note: when a promise is passed as the output, all the modules that depend on this output must understand that the result is a promise    
	cb(null,{});
};

Refer test\modules*.js for more information on how modules can be structured and used.