Skip to content

Commit

Permalink
Writing 503 as status code when the external service is not respondin…
Browse files Browse the repository at this point in the history
…g while doing health checks
  • Loading branch information
diptanu committed Oct 31, 2014
1 parent d468bb2 commit c5069ab
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Observable<Void> handle(HttpServerRequest<ByteBuf> serverRequest, final H
String externalHealthCheckURL = DynamicProperty.getInstance("prana.host.healthcheck.url").getString("http://localhost:7001/healthcheck");
serverResponse.getHeaders().add("Content-Type", "application/xml");
if (Strings.isNullOrEmpty(externalHealthCheckURL)) {
serverResponse.setStatus(HttpResponseStatus.OK);
serverResponse.writeBytes("<health>ok</health>".getBytes());
return serverResponse.close();
}
Expand All @@ -38,15 +39,18 @@ public Observable<Void> handle(HttpServerRequest<ByteBuf> serverRequest, final H
@Override
public Observable<Void> call(HttpClientResponse<ByteBuf> response) {
if (response.getStatus().code() == HttpResponseStatus.OK.code()) {
serverResponse.setStatus(HttpResponseStatus.OK);
serverResponse.writeBytes("<health>ok</health>".getBytes());
return serverResponse.close();
}
serverResponse.setStatus(HttpResponseStatus.SERVICE_UNAVAILABLE);
serverResponse.writeBytes("<health>fail</health>".getBytes());
return serverResponse.close();
}
}).onErrorFlatMap(new Func1<OnErrorThrowable, Observable<Void>>() {
@Override
public Observable<Void> call(OnErrorThrowable onErrorThrowable) {
serverResponse.setStatus(HttpResponseStatus.SERVICE_UNAVAILABLE);
serverResponse.writeBytes("<health>fail</health>".getBytes());
return serverResponse.close();
}
Expand Down

0 comments on commit c5069ab

Please sign in to comment.