1
1
mirror of https://github.com/MarginaliaSearch/MarginaliaSearch.git synced 2025-10-06 17:32:39 +02:00

Compare commits

...

1 Commits

Author SHA1 Message Date
Viktor Lofgren
18e91269ab (crawler) Improve deferred task behavior 2025-03-18 12:25:22 +01:00

View File

@@ -267,7 +267,7 @@ public class CrawlerMain extends ProcessMainClass {
// Start every task we currently can from the deferral list // Start every task we currently can from the deferral list
deferredTasks.removeIf(task -> { deferredTasks.removeIf(task -> {
if (task.canRun()) { if (task.canRun()) {
if (pendingCrawlTasks.putIfAbsent(crawlSpec.domain(), task) != null) { if (pendingCrawlTasks.putIfAbsent(task.domain, task) != null) {
return true; // task has already run, duplicate in crawl specs return true; // task has already run, duplicate in crawl specs
} }
@@ -280,12 +280,23 @@ public class CrawlerMain extends ProcessMainClass {
}); });
} }
// Schedule any lingering tasks for immediate execution
for (var task : deferredTasks) {
if (pendingCrawlTasks.putIfAbsent(task.domain, task) != null)
continue;
pool.submitQuietly(task); // Schedule any lingering tasks for immediate execution until none exist
while (!deferredTasks.isEmpty()) {
deferredTasks.removeIf(task -> {
if (task.canRun()) {
if (pendingCrawlTasks.putIfAbsent(task.domain, task) != null) {
return true; // task has already run, duplicate in crawl specs
}
// This blocks the caller when the pool is full
pool.submitQuietly(task);
return true;
}
return false;
});
TimeUnit.MILLISECONDS.sleep(50);
} }
logger.info("Shutting down the pool, waiting for tasks to complete..."); logger.info("Shutting down the pool, waiting for tasks to complete...");