From ad31a22fbb7c6ae576f0904259a09f42191f7755 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Sun, 5 Oct 2025 10:32:05 +0200 Subject: [PATCH] (ndp) Refresh the ndp queue on restart --- .../java/nu/marginalia/ndp/DomainTestingQueue.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/processes/new-domain-process/java/nu/marginalia/ndp/DomainTestingQueue.java b/code/processes/new-domain-process/java/nu/marginalia/ndp/DomainTestingQueue.java index 11ee90a5d..e2efab03e 100644 --- a/code/processes/new-domain-process/java/nu/marginalia/ndp/DomainTestingQueue.java +++ b/code/processes/new-domain-process/java/nu/marginalia/ndp/DomainTestingQueue.java @@ -38,6 +38,7 @@ public class DomainTestingQueue { this.dataSource = dataSource; this.linkGraphClient = linkGraphClient; + Thread.ofPlatform() .name("DomainTestingQueue::fetch()") .start(this::fetch); @@ -92,6 +93,13 @@ public class DomainTestingQueue { } public void fetch() { + try (var conn = dataSource.getConnection()) { + refreshQueue(conn); + } catch (Exception e) { + logger.error("Error refreshing the ndp queue"); + throw new RuntimeException(e); + } + while (true) { List domains = new ArrayList<>(2000); try (var conn = dataSource.getConnection(); @@ -126,6 +134,7 @@ public class DomainTestingQueue { throw e; // Rethrow runtime exceptions to avoid wrapping them in another runtime exception } catch (Exception e) { + logger.error("Error in ndp process"); throw new RuntimeException("Failed to fetch domains from database", e); } @@ -193,7 +202,8 @@ public class DomainTestingQueue { /* Insert new domains into NDP_NEW_DOMAINS table */ try (var insertStmt = conn.prepareStatement(""" - INSERT IGNORE INTO NDP_NEW_DOMAINS (DOMAIN_ID, PRIORITY) VALUES (?, ?) + INSERT INTO NDP_NEW_DOMAINS (DOMAIN_ID, PRIORITY) VALUES (?, ?) + ON CONFLICT(DOMAIN_ID) DO UPDATE SET PRIORITY = excluded.PRIORITY """)) { conn.setAutoCommit(false);