89-time-series-by-cron #90

Merged
romanov73 merged 5 commits from 89-time-series-by-cron into master 2023-02-20 10:16:33 +04:00
2 changed files with 8 additions and 8 deletions
Showing only changes of commit a5c9d15d4f - Show all commits

View File

@ -22,13 +22,13 @@ public class ScheduledTimeSeriesService {
this.branchService = branchService; this.branchService = branchService;
} }
@Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") @Scheduled(cron = "0 0 * * * *", zone = "Europe/Samara")
public void addTimeSeriesPoints() { public void addTimeSeriesPoints() {
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); log.debug("Старт добавления новых точек временного ряда");
List<Branch> branches = branchService.findAll(); List<Branch> branches = branchService.findAll();
branches.forEach(branch -> { branches.forEach(branch -> {
scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch));
}); });
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); log.debug("Завершение добавления новых точек временного ряда");
} }
} }

View File

@ -47,13 +47,13 @@ public class TimeSeriesService {
@Transactional @Transactional
public TimeSeries save(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType, List<TimeSeriesValue> timeSeriesValues) { public TimeSeries save(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType, List<TimeSeriesValue> timeSeriesValues) {
LOG.debug("Start save {} time series with {} time series values ", timeSeriesName, timeSeriesValues.size()); LOG.debug("Начало сохранения временного ряда {} с {} значениями", timeSeriesName, timeSeriesValues.size());
final TimeSeries timeSeries = findOrCreate(timeSeriesName, branch, timeSeriesType); final TimeSeries timeSeries = findOrCreate(timeSeriesName, branch, timeSeriesType);
List<TimeSeriesValue> timeSeriesValuesToRemove = timeSeries.getValues(); List<TimeSeriesValue> timeSeriesValuesToRemove = timeSeries.getValues();
timeSeries.setValues(timeSeriesValues); timeSeries.setValues(timeSeriesValues);
LOG.debug("Save time series {} ", timeSeries.getName()); LOG.debug("Сохранение временного ряда {} ", timeSeries.getName());
TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries); TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries);
LOG.debug("Clear {} time series values ", timeSeriesValuesToRemove.size()); LOG.debug("Очистить {} точек временного ряда", timeSeriesValuesToRemove.size());
timeSeriesValueRepository.deleteAll(timeSeriesValuesToRemove); timeSeriesValueRepository.deleteAll(timeSeriesValuesToRemove);
sendToTimeSeriesService(savedTimeSeries); sendToTimeSeriesService(savedTimeSeries);
return savedTimeSeries; return savedTimeSeries;
@ -100,7 +100,7 @@ public class TimeSeriesService {
new Thread(() -> { new Thread(() -> {
try { try {
httpService.post(TIME_SERIES_SAVE_SERVICE_URL, new JSONObject(new JsonTimeSeries(timeSeries))); httpService.post(TIME_SERIES_SAVE_SERVICE_URL, new JSONObject(new JsonTimeSeries(timeSeries)));
LOG.debug("Успешно отправлен на сервис"); LOG.debug("{} успешно отправлен на сервис временных рядов", timeSeries.getName());
} catch (Exception ex) { } catch (Exception ex) {
LOG.debug(ex.getMessage()); LOG.debug(ex.getMessage());
} }
@ -113,7 +113,7 @@ public class TimeSeriesService {
public TimeSeries getById(Integer tsId) { public TimeSeries getById(Integer tsId) {
return timeSeriesRepository.findById(tsId) return timeSeriesRepository.findById(tsId)
.orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); .orElseThrow(() -> new RuntimeException("Временной ряд не найден по идентификатору " + tsId));
} }
public List<TimeSeriesType> getAllTimeSeriesTypes() { public List<TimeSeriesType> getAllTimeSeriesTypes() {