Skip to content

Commit

Permalink
fix: cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed May 20, 2024
1 parent 7471688 commit 6efb0b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.time.Instant;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

import org.slf4j.Logger;
Expand Down Expand Up @@ -78,7 +81,7 @@ public void scheduledImporterSymbols() {
LOGGER.info(this.symbolImportService.importHkSymbols());
LOGGER.info(this.symbolImportService.importUsSymbols());
this.symbolImportService.refreshSymbolEntities();
LOGGER.info("scheduledImporterSymbols: {}ms", start.toEpochMilli() - Instant.now().toEpochMilli());
LOGGER.info("scheduledImporterSymbols: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}

private void importCurrencyQuotes() {
Expand All @@ -88,7 +91,7 @@ private void importCurrencyQuotes() {
LOGGER.info("Import of {} Usd quotes finished.",
this.currencyService.importFxDailyQuoteHistory(DataHelper.CurrencyKey.USD.toString()));
this.currencyService.initCurrencyMap();
LOGGER.info("importCurrencyQuotes: {}ms", start.toEpochMilli() - Instant.now().toEpochMilli());
LOGGER.info("importCurrencyQuotes: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}

@Transactional
Expand All @@ -103,23 +106,30 @@ public void scheduledImporterRefIndexes() {
mySymbol -> this.quoteImportService.importUpdateDailyQuotes(mySymbol, new UserKeys(this.apiKey, null)))
.reduce(0L, (acc, value) -> acc + value);
LOGGER.info("Indexquotes import done for: {}", symbolCount);
LOGGER.info("scheduledImporterRefIndexes: {}ms", start.toEpochMilli() - Instant.now().toEpochMilli());
LOGGER.info("scheduledImporterRefIndexes: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}

@Scheduled(cron = "0 25 1 * * ?")
@Transactional
@Scheduled(cron = "0 20 1 * * ?")
@SchedulerLock(name = "CronJob_quotes", lockAtLeastFor = "PT10M", lockAtMostFor = "PT2H")
public void scheduledImporterQuotes() {
Instant start = Instant.now();
List<Symbol> symbolsToUpdate = this.symbolImportService.findSymbolsToUpdate();
this.symbolImportService.updateSymbolQuotes(symbolsToUpdate);
LOGGER.info("scheduledImporterQuotes: {}ms", start.toEpochMilli() - Instant.now().toEpochMilli());
try {
var numSym = this.symbolImportService.updateSymbolQuotes(symbolsToUpdate).get(110L, TimeUnit.MINUTES);
LOGGER.info("Symbols updated: {}", numSym);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException("SymbolImport failed.",e);
}
LOGGER.info("scheduledImporterQuotes: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}

@Scheduled(cron = "0 45 1 * * ?")
@Transactional
@Scheduled(cron = "0 40 1 * * ?")
@SchedulerLock(name = "CronJob_portfolios", lockAtLeastFor = "PT10M", lockAtMostFor = "PT2H")
public void scheduledUpdatePortfolios() {
Instant start = Instant.now();
this.portfolioService.findAllPortfolios().forEach(myPortfolio -> this.portfolioService.updatePortfolioValues(myPortfolio));
LOGGER.info("scheduledUpdatePortfolios: {}ms", start.toEpochMilli() - Instant.now().toEpochMilli());
LOGGER.info("scheduledUpdatePortfolios: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down

0 comments on commit 6efb0b3

Please sign in to comment.