-
Notifications
You must be signed in to change notification settings - Fork 16
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
Implement clean shutdown code via bedrock.exit() #60
Comments
this sounds good. I will work on this when time allows. Just so there is more context for this issue. The problem is we are not cleaning up promises when bedrock shuts down resulting in Node throwing and then Mocha throwing an uncaught Exception after the test has run. |
one idea is to make a new function in bedrock.utils.cancellable = ({events = [], action}) => new Promise(async (resolve, reject) => {
for(const event of events) {
// we could make this configurable to also call on resolve
bedrock.events.on(event, () => reject(new Error(`Action cancelled by event ${event}`)));
}
const result = await action();
// FIXME unsubscribe from events here.
resolve(result);
}); This is meta-code and does not handle situations such as wanting to cancel with a reject for some events and a resolve for others, but it would allow: const {cancellable} = bedrock.utls;
const FireForgetCancel = await cancellable({events: ['exit'], action: watchMongo}); This would allow async functions that might be running on |
https://developer.mozilla.org/en-US/docs/Web/API/AbortController Node Docs: |
We now emit the |
We need to implement cleaner shutdown code via
bedrock.exit()
. Whenbedrock.exit()
is called, abedrock.exit
event should be emitted that is awaited on all workers -- and new workers should be prevented from starting up. Once all workers have exited, we can call cluster kill. A flag can be provided tobedrock.exit()
with an optional timeout that will forcibly call cluster kill after the timeout.The text was updated successfully, but these errors were encountered: