Skip to content

Application

do- edited this page Aug 27, 2026 · 44 revisions

Application is a container class that combines a registry of modules with namingConventions and resource poolss necessary for executing business methods.

The purpose of Application is to host JobSources that produce Jobs to execute business methods: either for incoming requests or based on internal schedules.

Constructor

Though it is not necessary, the Application class is presumed to be inherited from, so its constructor should be called as super ():

const {Application} = require ('doix')

class MyApplication extends Application () {

  constructor (conf) {

    super ({

      globals: {
        conf
      },

      generators: {
        uuid: uuid.v4 () // just an example, no dependency
      },

      pools: {
        db: new DbPoolPg (conf.db)
      },

      modules: { // all ModuleMap options
        dir: {
          root: ['/opt/myProject'], 
//        filter: (str, arr) => arr.at (-1) === 'Content'
//        live: config.debug,
        },
//      ext: '.js',
//      watch: config.debug,
//      merger: new myObjectMerger (someOptions)
      }, 

//    methodSelector: myMethodSelector,

    })

  }

}

The only parameter here is a bag of options (see below).

Options

Name Default value Description
globals see Default globals below an object of properties to be injected in each new job as is. For function valued properties, this works like using mixins.
generators {} an object of functions to calculate properties injected in each new job
handlers {} a bag of event handlers to be set for each new job
pools {} an object of ResourcePools to inject proxies to necessary shared resources in each new job
modules a ModuleMap options object.
namingConventions new NamingConventions () a NamingConventions descendant instance
logger A winston Logger
jobClass Job Default jobClass value for all JobSources in this application

Default globals

app: this,
[Tracker.LOGGING_EVENTS]: {
  method: {
    level: 'info',
      message: s => s,
      details: function () {return this.request},
    },		
    finish: {
      level: 'info',
      message: s => s,
      elapsed: true,
    }
}

Properties

Name Default value
defaultJobSource The first JobSource created with the reference to this application instance
jobSources The Map of all JobSources registered with tis Application, indexed by name

Methods

Public

exec (request = {}, options = {})

This asynchronous method creates a Job instance, awaits its outcome and returns the value obtained or rethrows the error occured. Shortcut to defaultJobSource.exec.

spawn (request = {}, options = {})

This synchronous method creates a Job instance, launches its workflow and exits immediately. Shortcut to defaultJobSource.spawn.

Internal

getMethod (request)

Uses namingConventions to derive moduleName and methodName from the given request, then calls modules.getMethod (moduleName, methodName)

Clone this wiki locally