fix(startup): Added hooks for async startup

This commit is contained in:
Chris Troutner
2022-06-27 10:09:08 -07:00
parent 0333f77f5a
commit f117fe15df
9 changed files with 57 additions and 8 deletions
+6 -1
View File
@@ -46,7 +46,12 @@ class Adapters {
}
// Start the IPFS node.
await this.ipfs.start()
// Do not start these adapters if this is an e2e test.
if (this.config.env !== 'test') {
await this.ipfs.start()
}
console.log('Async Adapters have been started.')
return true
} catch (err) {
+17 -6
View File
@@ -25,14 +25,14 @@ class Controllers {
this.useCases = new UseCases({ adapters: this.adapters })
}
async attachControllers (app) {
// Wait for any startup processes to complete for the Adapters libraries.
// Spin up any adapter libraries that have async startup needs.
async initAdapters () {
await this.adapters.start()
}
// Attach the REST controllers to the Koa app.
// this.attachRESTControllers(app)
this.attachRPCControllers()
// Run any Use Cases to startup the app.
async initUseCases () {
await this.useCases.start()
}
// Top-level function for this library.
@@ -47,6 +47,17 @@ class Controllers {
restControllers.attachRESTControllers(app)
}
// Attach any other controllers other than REST API controllers.
async attachControllers (app) {
// Wait for any startup processes to complete for the Adapters libraries.
// await this.adapters.start()
// Attach the REST controllers to the Koa app.
// this.attachRESTControllers(app)
this.attachRPCControllers()
}
// Add the JSON RPC router to the ipfs-coord adapter.
attachRPCControllers () {
const jsonRpcController = new JSONRPC({
+11
View File
@@ -18,6 +18,17 @@ class UseCases {
// console.log('use-cases/index.js localConfig: ', localConfig)
this.user = new UserUseCases(localConfig)
}
// Run any startup Use Cases at the start of the app.
async start () {
try {
console.log('Async Use Cases have been started.')
} catch (err) {
console.error('Error in use-cases/index.js/startUseCases()')
console.log(err)
throw err
}
}
}
module.exports = UseCases