@@ -0,0 +1,47 @@
|
||||
package ru.soune.nocopy.scheduler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
|
||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||
import ru.soune.nocopy.service.monitoring.MonitoringSearchService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MonitoringScheduler {
|
||||
|
||||
private final FileMonitoringRepository monitoringRepository;
|
||||
|
||||
private final MonitoringSearchService monitoringSearchService;
|
||||
|
||||
@Scheduled(cron = "0 1 2 * * *", zone = "Europe/Moscow")
|
||||
@Transactional
|
||||
public void processScheduledMonitoring() {
|
||||
log.info("Starting scheduled monitoring check at 02:01 MSK");
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<FileMonitoringEntity> readyForRun = monitoringRepository.findReadyForRun(now);
|
||||
|
||||
log.info("Found {} files ready for monitoring", readyForRun.size());
|
||||
|
||||
//TODO check tokens for apply
|
||||
for (FileMonitoringEntity monitoring : readyForRun) {
|
||||
try {
|
||||
monitoringSearchService.processFileSearch(monitoring);
|
||||
log.info("Successfully queued search for file: {}", monitoring.getFile().getId());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to process monitoring for file: {}", monitoring.getFile().getId(), e);
|
||||
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
|
||||
monitoringRepository.save(monitoring);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user