Start basic CLI framework
This commit is contained in:
4
lib/src/error/ErrorWithContext.ts
Normal file
4
lib/src/error/ErrorWithContext.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
export default class ErrorWithContext extends Error {
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ export default class HttpServer extends LifecycleUnit {
|
||||
|
||||
const request_timeout: number = this.config.get('server.request_timeout', 15000)
|
||||
|
||||
Deno.signal(Deno.Signal.SIGINT).then(() => {
|
||||
this.logger.info('Closing server...', true)
|
||||
this._server.close()
|
||||
})
|
||||
|
||||
for await ( const native_request of this._server ) {
|
||||
let req: Request = this.make(Request, native_request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user