|
@@ -66,6 +66,8 @@ public class ResultRequestSpoolService {
|
|
|
private final int maxRetry;
|
|
private final int maxRetry;
|
|
|
private final long rateDelayMs;
|
|
private final long rateDelayMs;
|
|
|
private final long intervalSeconds;
|
|
private final long intervalSeconds;
|
|
|
|
|
+ private final int doneRetentionDays;
|
|
|
|
|
+ private final int deadRetentionDays;
|
|
|
private final Object activeLock = new Object();
|
|
private final Object activeLock = new Object();
|
|
|
private final AtomicLong sequence = new AtomicLong();
|
|
private final AtomicLong sequence = new AtomicLong();
|
|
|
private volatile boolean running = true;
|
|
private volatile boolean running = true;
|
|
@@ -100,6 +102,8 @@ public class ResultRequestSpoolService {
|
|
|
this.writeTimeoutMs = positiveLong(properties, "RESULT_REQUEST_WRITE_TIMEOUT_MS", 10000L);
|
|
this.writeTimeoutMs = positiveLong(properties, "RESULT_REQUEST_WRITE_TIMEOUT_MS", 10000L);
|
|
|
this.maxRetry = positiveInt(properties, "RESULT_REQUEST_MAX_RETRY", 20);
|
|
this.maxRetry = positiveInt(properties, "RESULT_REQUEST_MAX_RETRY", 20);
|
|
|
this.intervalSeconds = positiveLong(properties, "RESULT_REQUEST_INTERVAL_SECONDS", 300L);
|
|
this.intervalSeconds = positiveLong(properties, "RESULT_REQUEST_INTERVAL_SECONDS", 300L);
|
|
|
|
|
+ this.doneRetentionDays = positiveInt(properties, "RESULT_REQUEST_DONE_RETENTION_DAYS", 60);
|
|
|
|
|
+ this.deadRetentionDays = positiveInt(properties, "RESULT_REQUEST_DEAD_RETENTION_DAYS", 150);
|
|
|
int rate = positiveInt(properties, "RESULT_REQUEST_RATE_LIMIT_PER_SECOND", 10);
|
|
int rate = positiveInt(properties, "RESULT_REQUEST_RATE_LIMIT_PER_SECOND", 10);
|
|
|
this.rateDelayMs = Math.max(1L, 1000L / rate);
|
|
this.rateDelayMs = Math.max(1L, 1000L / rate);
|
|
|
this.queue = new ArrayBlockingQueue<Pending>(positiveInt(properties, "RESULT_REQUEST_QUEUE_CAPACITY", 10000));
|
|
this.queue = new ArrayBlockingQueue<Pending>(positiveInt(properties, "RESULT_REQUEST_QUEUE_CAPACITY", 10000));
|
|
@@ -224,6 +228,24 @@ public class ResultRequestSpoolService {
|
|
|
move(ready, claimed);
|
|
move(ready, claimed);
|
|
|
processFile(claimed);
|
|
processFile(claimed);
|
|
|
}
|
|
}
|
|
|
|
|
+ cleanupExpiredFiles(doneDir, "*.done", doneRetentionDays);
|
|
|
|
|
+ cleanupExpiredFiles(deadDir, "*.dead", deadRetentionDays);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void cleanupExpiredFiles(Path directory, String glob, int retentionDays) throws IOException {
|
|
|
|
|
+ long cutoff = System.currentTimeMillis()
|
|
|
|
|
+ - TimeUnit.DAYS.toMillis((long) retentionDays);
|
|
|
|
|
+ for (Path file : listFiles(directory, glob)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (Files.getLastModifiedTime(file).toMillis() < cutoff) {
|
|
|
|
|
+ Files.deleteIfExists(file);
|
|
|
|
|
+ logger.info("Deleted expired resultRequest spool file: " + file);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
|
+ logger.warn("Cannot delete expired resultRequest spool file " + file
|
|
|
|
|
+ + ": " + ex.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void rotateActiveFile() throws IOException {
|
|
private void rotateActiveFile() throws IOException {
|