I have an go application running 24 hours a day. Does anyone have an idea for a separate application that looks up whether the main application is running? If the main application has a bug, an additional application should close the main application and re-run the main application. Or maybe there is something in the style of the destructor, which could be the main application?
In case of returned error
s it's the task of your application to handle them correctly and restart the appropriate parts. It get's harder in case of panic
s. Here Go provides recover
. It's like a catch
of exceptions.
In https://github.com/tideland/goas I provide loop
, a package to run goroutines in a controlled way. Beside a traditional approach with the ability to stop a goroutine and/or retrieve an error value in case it died you can also start a goroutine with GoRecoverable
. It provides a way to pass a function that's called in case of a panic and also knows about count and frequency. So it can act or decide if a goroutine shall continue work (e.g. by resetting/re-initializing those parts of your code that are covered by the failure).