Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/framework-core/src/booster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class Booster {
* Initializes the Booster project
*/
public static start(codeRootPath: string): void {
registerShutdownSignalHandlers()
const projectRootPath = codeRootPath.replace(new RegExp(this.config.codeRelativePath + '$'), '')
this.config.userProjectRootPath = projectRootPath
Importer.importUserProjectFiles(codeRootPath)
Expand Down Expand Up @@ -210,3 +211,22 @@ function checkAndGetCurrentEnv(): string {
}
return env
}

function registerShutdownSignalHandlers(): void {
const signals = ['SIGINT', 'SIGTERM', 'SIGQUIT']
signals.forEach((signal) => {
process.on(signal, () => {
shutDownGracefully(signal)
})
})
}

function shutDownGracefully(signal: string): void {
console.log(`Received signal '${signal}'. Shutting down gracefully...`)
cleanup()
process.exit(0)
}

function cleanup(): void {
// Does Booster have dedicated clean up to do ?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BelgianNoise Booster currently does not have a dedicated cleanup upon shutdown, but I think it would be beneficial to implement one. It should probably:

  • Stop accepting incoming GraphQL connections/requests and close WebSocket connections.
  • Close connections to DB and read model stores (this would have to be provider-specific).
  • Close any other connections, such as to Event Hubs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your feedback, we have done some more internal debugging and found that it was an issue in our provider that was causing issues with the child process shenanigans & nyc.

That being said, this could still be a nice addition to the core package imo. However I won't be able to focus on it right now as I would need to find time outside working hours to make these changes and get more familiar with the code :)

I am stil eager to go deeper into the code and add the things you mentioned above, but it won't be in teh short term.
I will revert my PR back to a draft and I am leaving it up to you if you would rather see it closed for now.

(Feel free to hijack this PR if desired)

Edit: I do not have access to revert back to draft :)

(Oops, commented with diff account earlier)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BelgianNoise I think we can go ahead with this addition and eventually implement the cleanup method in future PRs :)

}
Loading