SUPPORT-9561: fix scheduler

This commit is contained in:
gulnaz 2025-11-25 17:25:10 +03:00
parent 70b4bdf0c4
commit 5c00196056
2 changed files with 7 additions and 3 deletions

View file

@ -90,10 +90,10 @@ public class ExcerptHistoryDao {
.execute(); .execute();
} }
public void deleteOld() { public void deleteOlderThan(long hours) {
dslContext.deleteFrom(EXCERPT_HISTORY) dslContext.deleteFrom(EXCERPT_HISTORY)
.where(EXCERPT_HISTORY.DATETIME.le( .where(EXCERPT_HISTORY.DATETIME.le(
Timestamp.valueOf(LocalDateTime.now().minus(1, ChronoUnit.HOURS)))) Timestamp.valueOf(LocalDateTime.now().minus(hours, ChronoUnit.HOURS))))
.execute(); .execute();
} }
} }

View file

@ -1,6 +1,7 @@
package ru.micord.ervu.scheduler; package ru.micord.ervu.scheduler;
import net.javacrumbs.shedlock.core.SchedulerLock; import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.micord.ervu.dao.ExcerptHistoryDao; import ru.micord.ervu.dao.ExcerptHistoryDao;
@ -13,6 +14,9 @@ public class ExcerptCleanScheduler {
private final ExcerptHistoryDao excerptHistoryDao; private final ExcerptHistoryDao excerptHistoryDao;
@Value("${excerpt.lifetime.hours:24}")
private long fileLifetime;
public ExcerptCleanScheduler(ExcerptHistoryDao excerptHistoryDao) { public ExcerptCleanScheduler(ExcerptHistoryDao excerptHistoryDao) {
this.excerptHistoryDao = excerptHistoryDao; this.excerptHistoryDao = excerptHistoryDao;
} }
@ -20,6 +24,6 @@ public class ExcerptCleanScheduler {
@Scheduled(fixedDelayString = "${excerpt.cleanup.delay:30000}") @Scheduled(fixedDelayString = "${excerpt.cleanup.delay:30000}")
@SchedulerLock(name = "oldExcerptFilesCleaning") @SchedulerLock(name = "oldExcerptFilesCleaning")
public void cleanOld() { public void cleanOld() {
excerptHistoryDao.deleteOld(); excerptHistoryDao.deleteOlderThan(fileLifetime);
} }
} }