Golang: a web service that monitors goroutines
Suppose I am writing a REST web service in golang. Inside, I have a few workers doing things. Such a goroutine is triggered by an HTTP API request. Of course, I would like to somehow monitor the progress of these gutturals. There will usually be a channel for news, bugs, etc. And the main program will be doing
on these channels.
However, since the even loop of the main program is busy
, I see no way to achieve this. Given that this seems like a fairly common problem, I am wondering if there is a design pattern I am missing.
[EDIT] Some more technical details. Therefore I have a class
that manages the resource pool.
is a long operation, so it will be a blow of the guttrum in the background. The channel will be open to allow status.
When an HTTP request comes in, this one runs
. But I have no context for polling the status. My silly plan currently is to poll the channel for input when the next HTTP request comes in. This should be enough, but not ideal - I'd like to know what's going on in this goroutine right away.
source to share