*Blog* mariocarrion.com/ *Example code* github.com/MarioCarrion/todo-api-microservice-example/tree/76509a58cabf95bb8329da4e8bf41986885ba814 *Building Microservices in Go* kzbin.info/aero/PL7yAAGMOat_Fn8sAXIk0WyBfK_sT1pohu *Go Tools and Packages* kzbin.info/aero/PL7yAAGMOat_HEEOvH99agDs_5g51A0Ls3 *Testing in Go* kzbin.info/aero/PL7yAAGMOat_HSeW4zF0uRL9EaHadE4ZZq *Keep it up!*
@0zema3 жыл бұрын
your content is a god-send, very clear and understandable with actual valuable information and insane quality!
@MarioCarrion3 жыл бұрын
Thanks Osama! Cheers
@josemontero9782 Жыл бұрын
Great video, one question, what does the ctx.WithTimeout(5 sec) do ? I know is being use for the srv.ShutDown function, but is there a especific thing for the 5 sec ? Is it to allow the Shutdown function time to finish ?
@MarioCarrion Жыл бұрын
It creates a context that will time out in 5 seconds; in practice, this means: "wait up to 5 seconds or just exit right away". To be fair, 5 seconds looks like a magic number, but it's usually more than enough to close all existing connections; in the end, depending on how you're scaling up/down, like the orchestration system you're using, will override this anyways.
@SirRFI3 жыл бұрын
So, to my understanding, graceful shutdown you described just tries to stop everything as soon as it's safe to do so (close connections etc.). What if I wanted it to finish ongoing requests first, without accepting new?
@MarioCarrion3 жыл бұрын
For this specific case (http.Server), the "Shutdown" method does what you're describing: it closes all open listeners, then idle connections and finally it waits indefinitely for any connection until they become idle so those can be closed; but if the received context defines a deadline then that one honored as well. However things get a bit complicated because the process that triggered the stop will eventually try to forcibly terminate it if that one is still running, that's why using the configured "grace period" becomes useful in those cases; if we are talking about long running processes perhaps defining a way to "resume" those processes could make sense.