NCBACK-27 fix token life
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-01-10 02:09:39 +07:00
parent 3e06040123
commit 2b7a8b97e1
3 changed files with 9 additions and 8 deletions
@@ -25,14 +25,13 @@ public class CleanupTokenSessionsService {
@Transactional
@Scheduled(fixedDelay = 30000)
public void cleanupExpiredFiles() {
LocalDateTime hourBefore = LocalDateTime.now().minusHours(authTokenLife);
public void cleanupExpiredTokens() {
LocalDateTime now = LocalDateTime.now();
List<AuthToken> tokensForDelete = authTokenRepository.findByLastUsedAtBefore(hourBefore).stream().toList();
List<AuthToken> tokensDeleteWithNullUpdate = authTokenRepository.findByLastUsedAtAndExpiresAtBefore(
null, hourBefore).stream().toList();
List<AuthToken> expiredTokens = authTokenRepository.findByExpiresAtBefore(now);
authTokenRepository.deleteAll(tokensForDelete);
authTokenRepository.deleteAll(tokensDeleteWithNullUpdate);
if (!expiredTokens.isEmpty()) {
authTokenRepository.deleteAll(expiredTokens);
}
}
}