-
Notifications
You must be signed in to change notification settings - Fork 1
Application
do- edited this page Aug 29, 2024
·
39 revisions
Application
is a container class that combines a registry of modules
with namingConventions
and resource pools
s necessary for executing business methods.
The purpose of Application
is to host JobSource
s that produce Job
s to execute business methods: either for incoming requests or based on internal schedules.
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).
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 |
{uuid: randomUUID} |
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 |
app: this,
[Tracker.LOGGING_EVENTS]: {
method: {
level: 'info',
message: s => s,
details: function () {return this.request},
},
finish: {
level: 'info',
message: s => s,
elapsed: true,
}
}
Uses namingConventions
to derive moduleName
and methodName
from the given request
, then calls modules.getMethod (moduleName, methodName)