Files
no-copy/src/main/java/ru/soune/nocopy/service/auth/CleanupTokenSessionsService.java
T

38 lines
1.1 KiB
Java
Raw Normal View History

2026-01-05 16:26:46 +07:00
package ru.soune.nocopy.service.auth;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
2026-01-21 12:21:14 +07:00
import ru.soune.nocopy.entity.user.AuthToken;
2026-01-05 16:26:46 +07:00
import ru.soune.nocopy.repository.AuthTokenRepository;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class CleanupTokenSessionsService {
@Autowired
private AuthTokenRepository authTokenRepository;
@Value("${file.storage.auth-token-life-hours}")
private int authTokenLife;
@Transactional
@Scheduled(fixedDelay = 30000)
2026-01-10 02:09:39 +07:00
public void cleanupExpiredTokens() {
LocalDateTime now = LocalDateTime.now();
2026-01-05 16:26:46 +07:00
2026-01-10 02:09:39 +07:00
List<AuthToken> expiredTokens = authTokenRepository.findByExpiresAtBefore(now);
2026-01-05 16:26:46 +07:00
2026-01-10 02:09:39 +07:00
if (!expiredTokens.isEmpty()) {
authTokenRepository.deleteAll(expiredTokens);
}
2026-01-05 16:26:46 +07:00
}
}