Compare commits

..

3 Commits

2 changed files with 18 additions and 12 deletions

View File

@ -32,7 +32,7 @@ public class PendingImportScannerTask {
for (var job : pendingJobs) {
if (!s3Service.objectExists(job.getS3FileKey())) {
return;
continue;
}
log.info("Found file for job {} in S3: {}", job.getId(), job.getS3FileKey());

View File

@ -1,13 +1,16 @@
package com.magamochi.ingestion.task;
import com.magamochi.ingestion.client.FlareClient;
import com.magamochi.ingestion.model.entity.FlareSession;
import com.magamochi.ingestion.service.FlareSessionRegistry;
import java.time.Duration;
import java.time.Instant;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Log4j2
@Component
@RequiredArgsConstructor
public class FlareSessionCleanupTask {
@ -18,18 +21,21 @@ public class FlareSessionCleanupTask {
@Scheduled(fixedDelayString = "1m")
public void cleanExpiredSessions() {
registry
.getSessions()
.forEach(
(provider, session) -> {
if (Duration.between(session.lastAccess(), Instant.now()).compareTo(TIMEOUT) <= 0) {
return;
}
registry.getSessions().forEach(this::destroySession);
}
client.destroySession(
FlareClient.SessionDestroyRequest.builder().session(session.sessionId()).build());
public void destroySession(String provider, FlareSession session) {
if (Duration.between(session.lastAccess(), Instant.now()).compareTo(TIMEOUT) <= 0) {
return;
}
registry.remove(provider);
});
try {
client.destroySession(
FlareClient.SessionDestroyRequest.builder().session(session.sessionId()).build());
} catch (Exception e) {
log.warn("Failed to destroy session for provider {}: {}", provider, e.getMessage());
}
registry.remove(provider);
}
}