Skip to content

Commit

Permalink
add health check and port
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jan 15, 2024
1 parent f295f1e commit 5ecf5b4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/opendota/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
public class Main {

public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(Integer.valueOf(args.length > 0 ? args[0] : "5600")), 0);
HttpServer server = HttpServer.create(new InetSocketAddress(Integer.valueOf("5600")), 0);
server.createContext("/", new MyHandler());
server.createContext("/healthz", new HealthHandler());
server.createContext("/blob", new BlobHandler());
server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool());
server.start();
Expand Down Expand Up @@ -52,6 +53,16 @@ public void handle(HttpExchange t) throws IOException {
}
}

static class HealthHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
t.sendResponseHeaders(200, 2);
OutputStream os = t.getResponseBody();
os.write("ok".getBytes());
os.close();
}
}

static class BlobHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
Expand Down Expand Up @@ -143,7 +154,7 @@ public void run()
ip = RegisterTask.shellExec("hostname -i");
}
int nproc = Runtime.getRuntime().availableProcessors();
RegisterTask.shellExec("curl -X POST -L" + System.getenv().get("SERVICE_REGISTRY_HOST") + "/register/parser/" + ip + "?size=" + nproc);
RegisterTask.shellExec("curl -X POST -L" + System.getenv().get("SERVICE_REGISTRY_HOST") + "/register/parser/" + ip + ":5600" + "?size=" + nproc);
} catch (Exception e) {
System.err.println(e);
}
Expand Down

0 comments on commit 5ecf5b4

Please sign in to comment.