samber / do

⚙️ A dependency injection toolkit based on Go 1.18+ Generics.
https://pkg.go.dev/github.com/samber/do
MIT License
1.82k stars 75 forks source link

Proposal: do.Shutdown returning shutdown time ? #32

Open samber opened 1 year ago

samber commented 1 year ago

My monolith application relies a lot on do.Shutdownable interface. Some tasks call database or third-parties, and flush buffer.

I would like to measure the time of the do.Shutdown processing.

API proposal: duration, err := do.Shutdown()

duration would be either a time.Duration or:

type ShutdownDuration struct {
    All time.Duration
    Services map[string]time.Duration
}

WDYT ?

GreyXor commented 1 year ago

Hello, thanks for this proposal. I like this idea, my 2 cents here is :

If we already return information about the shutdown, perhaps we can also return several other informations. e.g. the number of services actually closed, the time elapsed, potential errors. My proposal : shutdownFeedback, err := do.Shutdown()

type ShutdownFeedback struct {
    All time.Duration
    Services map[string]time.Duration
    ServicesError map[string]error // each errors returned by each services shutdown
    servicesTurnedOff int
   // maybe something else ?
}