apprunner

Manage application errors and plugin modules by Harald Rudell

App Runner

App Runner allows to to generate and maintain many apps using shared code. Require is great, App Runner is greater!

App Runner does three things:

  • Provides loadable apis
  • Manages application errors
  • Emails anomaly reports

Why App Runner? App Runner is App Lego.

If you make many Web apps and you have several of them for example accessing Facebook or using the same type of database, App Runner enables you to architect that in a repeatable pattern. App Runner allows you to use json to configure where code comes from and its settings.

Reference

App Runner handles process exceptions and SIGINT.

  • Exit code 0 is SIGINT
  • Exit code 2 is unhandled exception
  • defaults: options, typically loaded by haraldops

    • .init.appFolder: string: the folder of initial script
    • .init.logger: optional function(string): logging, default console.log
    • .init.ops.sendMail: optional function(subject, body): Sends mail, default none
    • .api: optional, indicates that Api Manager should be used
    • .api.apiMap: api configurations
  • app: Web server, has .on and .get methods

  • cb(err): optional function

get an api implementation

  • opts: object
  • .api: string: name of api function to be loaded
  • cb(err, module)

APIs are either configured directly in opts, or in defaults provided at App Runner init

If module has module.emitter, APp Runner will listen and manage error events

Report any argument as an anomaly, to the log and if so configured a periodcal email.

control emailing on or off: flag: boolean, default: false

Ensures that all callbacks has completed

var haraldutil = require('haraldutil')
var cbc = haraldutil.getCbCounter()
setTimeout(cbc.add(callback), 100)
setTimeout(cbc.add(callback), 100)
 
function callback() {
  if (cbc.isDone(arguments.callee))
    console.log('All callbacks completed.')
  else console.log('Not done yet...')
}
Not done yet...
All callbacks completed.

var cbc = getCbCounter(opts)

  • opts: optional object

  • opts.emitter: optional event emitter or boolean. default: errors are thrown

    • false: errors are ignored
    • emitter: errors are emitted
  • opts.callback: function or array of function: add is done for each function

cbc: object

  • .add(f): adds a callback for function f, return value: f
  • .isDone(f): notes one callback completed. returns true if all callbacks complete, otherwise false
  • .getStatus(): gets an object representing the current state

Examples

TODO

Notes

(c) Harald Rudell wrote this for node in September, 2012

No warranty expressed or implied. Use at your own risk.

Please suggest better ways, new features, and possible difficulties on github