Answer the question
In order to leave comments, you need to log in
How to put the application "on pause"?
Hey!
Simplified:
There is a golang application that receives data via http from an external server once a second, somehow processes them and sends them back.
If the server returns code 500 upon receiving data, then it is necessary to pause the application: stop processing already received data and send the processed data back to the server (technically, this will mean clearing buffered channels and data that is already spinning inside the application).
As soon as the response from the server comes 200, everything continues to work again.
Please tell me links with examples of how best to manage such a kind of global state of the application.
Answer the question
In order to leave comments, you need to log in
I have never written in Go, but I can ask a smart question about the architecture. =)
As soon as the response from the server comes 200, everything continues to work again.
while (true) {
data = query_server();
result = process_data(data);
send_result(result);
}
It's all wrong somehow.
If there is a request, then there is a connection. Until a response is returned, the web server must keep the connection. And if no response is returned, then the client waits until the connection times out. So this technique is quite costly in terms of resources that can be exhausted. Especially if you have a large number of clients.
Well, and so, error 500 can mean both a logical and a connection error with the DBMS, and that some resource of the 3rd party is unavailable, and much more. So if it is logical, then the server will not "correct" and, at the same time, will not come out of hibernation if it waits for a response of 200.
Well, you can block execution using channels. But I don't see any practical use for it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question