Start basic CLI framework
This commit is contained in:
@@ -68,7 +68,16 @@ export default class Application {
|
||||
* @return Promise<void>
|
||||
*/
|
||||
async down() {
|
||||
this.logger.info('Stopping Daton...', true)
|
||||
for ( const unit of this.instantiated_units ) {
|
||||
if ( !unit ) continue
|
||||
await this.stop_unit(unit)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.logger.warn(`Force exiting...`)
|
||||
Deno.exit()
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,8 +115,25 @@ export default class Application {
|
||||
} catch (e) {
|
||||
unit.status = Status.Error
|
||||
this.logger.error(`Error encountered while starting ${unit.constructor.name}. Will attempt to proceed.`)
|
||||
this.logger.debug(e.message)
|
||||
this.logger.verbose(e)
|
||||
this.logger.debug(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down the given lifecycle unit.
|
||||
* @param {LifecycleUnit} unit
|
||||
*/
|
||||
protected async stop_unit(unit: LifecycleUnit) {
|
||||
try {
|
||||
unit.status = Status.Stopping
|
||||
this.logger.info(`Stopping ${unit.constructor.name}...`)
|
||||
await unit.down()
|
||||
this.logger.verbose(`Successfully stopped ${unit.constructor.name}`)
|
||||
unit.status = Status.Stopped
|
||||
} catch (e) {
|
||||
unit.status = Status.Error
|
||||
this.logger.error(`Error encountered while stopping ${unit.constructor.name}. Will attempt to proceed.`)
|
||||
this.logger.debug(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user