-
Notifications
You must be signed in to change notification settings - Fork 263
Handling DB cleanup correctly #765
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
Comments
Hi dude, I believe that your pain is valid to implement a new method like Init but with Shutdown. Even though not solve for whole your pain it will rather than. Well, I don't like using global variables. I'd make methods in my app to CloseDB(), which will call when you shut down your main See below: func Serve(ctx context.Context, e *implBFF) error {
fmt.Printf("BFF listener available on %v\n", e.bff.String())
f := fiber.New()
e.createRouter(ctx, f)
defer func(){
e.db.Close()
}()
return f.Listener(e.bff)
} @rgrandl What do you think of us implementing a |
Yes, I thought about that but it beats the purpose of using |
Similar to: #275 |
In the current implementation, we provide the user the ability to initialize things by implementing an `Init` method. However, they don't have the ability to do a clean shutdown easily. The user filled multiple github issues (#275 and #765) asking for a `Shutdown` method. This PR adds a `Shutdown` method to each component. Note that there is no guarantee that this method can run - e.g., the app receives a SIGKILL because the machine suddenly crashes. However, a `Shutdown` method can enable the user to achieve graceful shutdown in normal scenarios. In tests, if someone wants to test the `Shutdown` method, they can get a pointer to the implementation of the component and explicitly call the `Shutdown` method.
I created #766 to add a |
In the current implementation, we provide the user the ability to initialize things by implementing an `Init` method. However, they don't have the ability to do a clean shutdown easily. The user filled multiple github issues (#275 and #765) asking for a `Shutdown` method. This PR adds a `Shutdown` method to each component. Note that there is no guarantee that this method can run - e.g., the app receives a SIGKILL because the machine suddenly crashes. However, a `Shutdown` method can enable the user to achieve graceful shutdown in normal scenarios. In tests, if someone wants to test the `Shutdown` method, they can get a pointer to the implementation of the component and explicitly call the `Shutdown` method.
In the current implementation, we provide the user the ability to initialize things by implementing an `Init` method. However, they don't have the ability to do a clean shutdown easily. The user filled multiple github issues (#275 and #765) asking for a `Shutdown` method. This PR adds a `Shutdown` method to each component. Note that there is no guarantee that this method can run - e.g., the app receives a SIGKILL because the machine suddenly crashes. However, a `Shutdown` method can enable the user to achieve graceful shutdown in normal scenarios. In tests, if someone wants to test the `Shutdown` method, they can get a pointer to the implementation of the component and explicitly call the `Shutdown` method.
In the current implementation, we provide the user the ability to initialize things by implementing an `Init` method. However, they don't have the ability to do a clean shutdown easily. The user filled multiple github issues (#275 and #765) asking for a `Shutdown` method. This PR adds a `Shutdown` method to each component. Note that there is no guarantee that this method can run - e.g., the app receives a SIGKILL because the machine suddenly crashes. However, a `Shutdown` method can enable the user to achieve graceful shutdown in normal scenarios. In tests, if someone wants to test the `Shutdown` method, they can get a pointer to the implementation of the component and explicitly call the `Shutdown` method.
In the current implementation, we provide the user the ability to initialize things by implementing an `Init` method. However, they don't have the ability to do a clean shutdown easily. The user filled multiple github issues (#275 and #765) asking for a `Shutdown` method. This PR adds a `Shutdown` method to each component. Note that there is no guarantee that this method can run - e.g., the app receives a SIGKILL because the machine suddenly crashes. However, a `Shutdown` method can enable the user to achieve graceful shutdown in normal scenarios. In tests, if someone wants to test the `Shutdown` method, they can get a pointer to the implementation of the component and explicitly call the `Shutdown` method.
If you install the latest weaver version (v0.24.2) you should be able to add a |
Hello!
Thanks for your good work!
I was wondering what would be the best practice to handle DB (or otherwise) cleanup.
Components offer a way to do
Init()
but there is no hook for deinitialization, therefore I don't know how best to express something like that:I'm thinking that perhaps before serving the app, I could create a global variable and wait for the shutdown signal in a goroutine to do this but I'd like to have your opinion on this subject, if possible!
Thanks a lot for your time!
The text was updated successfully, but these errors were encountered: