mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
(crawler) Terminate crawler after a few hours of no progress
This commit is contained in:
parent
0f637fb722
commit
a497e4c920
@ -3,6 +3,7 @@ package nu.marginalia.util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
@ -47,12 +48,15 @@ public class SimpleBlockingThreadPool {
|
||||
this.shutDown = true;
|
||||
}
|
||||
|
||||
public void shutDownNow() {
|
||||
public void shutDownNow() throws InterruptedException {
|
||||
this.shutDown = true;
|
||||
tasks.clear();
|
||||
for (Thread worker : workers) {
|
||||
worker.interrupt();
|
||||
}
|
||||
for (Thread worker : workers) {
|
||||
worker.join(Duration.ofMinutes(5));
|
||||
}
|
||||
}
|
||||
|
||||
private void worker() {
|
||||
|
@ -151,12 +151,20 @@ public class CrawlerMain {
|
||||
logger.info("Shutting down the pool, waiting for tasks to complete...");
|
||||
|
||||
pool.shutDown();
|
||||
do {
|
||||
System.out.println("Waiting for pool to terminate... " + pool.getActiveCount() + " remaining");
|
||||
} while (!pool.awaitTermination(60, TimeUnit.SECONDS));
|
||||
int activePoolCount = pool.getActiveCount();
|
||||
|
||||
while (!pool.awaitTermination(5, TimeUnit.HOURS)) {
|
||||
int newActivePoolCount = pool.getActiveCount();
|
||||
if (activePoolCount == newActivePoolCount) {
|
||||
logger.warn("Aborting the last {} jobs of the crawl, taking too long", newActivePoolCount);
|
||||
pool.shutDownNow();
|
||||
} else {
|
||||
activePoolCount = newActivePoolCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
logger.warn("Exception in crawler", ex);
|
||||
}
|
||||
finally {
|
||||
heartbeat.shutDown();
|
||||
|
Loading…
Reference in New Issue
Block a user