Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
indexer: add delay funciton
Browse files Browse the repository at this point in the history
  • Loading branch information
T4ze committed Dec 9, 2017
1 parent e4f0271 commit 982897b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/com/epita/guereza/IndexerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.concurrent.*;

public class IndexerApp extends App {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexerApp.class);
private final Indexer indexer;
Expand Down Expand Up @@ -40,14 +43,25 @@ private void requestNextUrl() {
sendMessage("/request/indexer/url", subscribeUrl);
}

private void retryIn(final int seconds) {
LOGGER.info("Retry fetching url in {}seconds", seconds);
final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.schedule(this::requestNextUrl, seconds, TimeUnit.SECONDS);
executor.shutdownNow();
}

@Override
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
final String url = msg.getContent();
LOGGER.info("Receive url: {}", url);
indexAndPublish(url);
if (msg != null) {
final String url = msg.getContent();
LOGGER.info("Receive url: {}", url);
indexAndPublish(url);

requestNextUrl();
requestNextUrl();
} else {
retryIn(30);
}
});

requestNextUrl();
Expand Down

0 comments on commit 982897b

Please sign in to comment.