mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
(query-client) Add support for fault-tolerant requests to single node services
Adding a method importantCall that will retry a failing request on each route until it succeeds or the routes run out.
This commit is contained in:
parent
746a865106
commit
07b625c58d
@ -47,10 +47,11 @@ public class QueryClient {
|
|||||||
|
|
||||||
@CheckReturnValue
|
@CheckReturnValue
|
||||||
public QueryResponse search(QueryParams params) {
|
public QueryResponse search(QueryParams params) {
|
||||||
|
var query = QueryProtobufCodec.convertQueryParams(params);
|
||||||
|
|
||||||
return wmsa_qs_api_search_time.time(
|
return wmsa_qs_api_search_time.time(
|
||||||
() -> QueryProtobufCodec.convertQueryResponse(queryApiPool
|
() -> QueryProtobufCodec.convertQueryResponse(queryApiPool
|
||||||
.api()
|
.importantCall((api) -> api.query(query))
|
||||||
.query(QueryProtobufCodec.convertQueryParams(params))
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,22 @@ public class GrpcSingleNodeChannelPool<STUB> extends ServiceChangeMonitor {
|
|||||||
return stubConstructor.apply(getChannel());
|
return stubConstructor.apply(getChannel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Try to make the call go through. The function will cycle through
|
||||||
|
* available routes until exhaustion, and only then will it give up
|
||||||
|
*/
|
||||||
|
public <T> T importantCall(Function<STUB, T> function) {
|
||||||
|
for (int i = 0; i < channels.size(); i++) {
|
||||||
|
try {
|
||||||
|
return function.apply(api());
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
logger.error("API Exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ServiceNotAvailableException(serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
/** Get the channel that is most ready to use */
|
/** Get the channel that is most ready to use */
|
||||||
public ManagedChannel getChannel() {
|
public ManagedChannel getChannel() {
|
||||||
return channels
|
return channels
|
||||||
|
Loading…
Reference in New Issue
Block a user