Skip to content

Commit

Permalink
move liveness probe start to end of main method
Browse files Browse the repository at this point in the history
  • Loading branch information
artntek committed Apr 30, 2024
1 parent aedcb98 commit 6e5eef0
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/main/java/org/dataone/cn/indexer/IndexWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public class IndexWorker {
private String specifiedThreadNumberStr = null;
private int specifiedThreadNumber = 0;
private ExecutorService executor = null;
private ScheduledExecutorService scheduler;


/**
* Commandline main for the IndexWorker to be started.
* @param args
Expand All @@ -114,6 +113,7 @@ public static void main(String[] args) throws IOException, TimeoutException, Ser
loadExternalPropertiesFile(propertyFile);
IndexWorker worker = new IndexWorker();
worker.start();
startLivenessProbe();
}

/**
Expand Down Expand Up @@ -228,25 +228,9 @@ public IndexWorker(Boolean initialize) throws IOException, TimeoutException, Ser
initIndexParsers();
ObjectManager.getInstance();
OntologyModelService.getInstance();
startLivenessProbe();
}
}

private void startLivenessProbe() {
scheduler = Executors.newScheduledThreadPool(1);
Runnable task = () -> {
Path path = Paths.get("./livenessprobe");
try {
Files.createFile(path);
Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis()));
logger.info("IndexWorker.startLivenessProbe - starting livenessProbe");
} catch (IOException e) {
logger.error("IndexWorker.startLivenessProbe - failed to touch file: " + path, e);
}
};
scheduler.scheduleAtFixedRate(task, 0, 10, TimeUnit.SECONDS);
}

/**
* Initialize the RabbitMQ service
* @throws IOException
Expand Down Expand Up @@ -379,7 +363,7 @@ public void run() {
};
boolean autoAck = false;
rabbitMQchannel.basicConsume(INDEX_QUEUE_NAME, autoAck, consumer);
logger.info("IndexWorker.start - Calling basicConsume and waiting for the comming messages");
logger.info("IndexWorker.start - Calling basicConsume and waiting for the coming messages");
}

/**
Expand Down Expand Up @@ -496,6 +480,20 @@ private void indexOjbect(IndexQueueMessageParser parser, long deliveryTag, boole
public void stop() throws IOException, TimeoutException {
rabbitMQchannel.close();
rabbitMQconnection.close();
logger.info("IndexWorker.stop - stop the index queue conection.");
logger.info("IndexWorker.stop - stop the index queue connection.");
}

private static void startLivenessProbe() {
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Path path = Paths.get("./livenessprobe");
Runnable task = () -> {
try {
Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis()));
} catch (IOException e) {
logger.error("IndexWorker.startLivenessProbe - failed to update file: " + path, e);
}
};
scheduler.scheduleAtFixedRate(task, 0, 10, TimeUnit.SECONDS);
logger.info("IndexWorker.startLivenessProbe - livenessProbe started");
}
}

0 comments on commit 6e5eef0

Please sign in to comment.