-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service init/unload methods #290
Comments
You're right for now the services can't block the project to start and that was the plan I think and currently you're force to do it with trailpack (but it can be done locally and easily). For now you need to create a trailpack or use trailpack-bootstrap to initialize services but it didn't block the project to start |
Sort of; Trails v2 has a bug in its config merging logic that makes the developer unable to properly override trailpack configs, but in Trails v3 the mechanism for accomplishing this is as follows:
constructor (app) {
super(app)
// ... custom stuff
this.app.emit('MyService:ready')
// config/trailpacks.js
module.exports = {
hapi: {
lifecycle: {
listen: [
'MyService:ready'
]
}
}
} This will ensure that trails will complete its startup process only when both the Service and the trailpack are done. But, like I said, this will not currently work in Trails v2. If your this.app.on('trailpack:foobar:initialized', () => {
// init logic |
Issue Description
Looking at the Service API (https://trailsjs.io/doc/en/ref/service) I was a bit surprised to see there are no initialize() and unload() methods. Services are singleton instances intended to do the applications heavy lifting right? I had expected the possibility to eg. block the applications start until my Service has connected to a different service. At the moment it would always be necessary to write a trailpack when the service would require any form of bootup and shutdown logic.
Is this an intended design decision?
(If not,) would you be open to change that?
Environment
The text was updated successfully, but these errors were encountered: