|
@@ -6,6 +6,7 @@ import com.danielbohry.stocks.repository.snapshot.PortfolioSnapshotEntity;
|
|
|
import com.danielbohry.stocks.repository.snapshot.SnapshotRepository;
|
|
import com.danielbohry.stocks.repository.snapshot.SnapshotRepository;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -26,6 +27,7 @@ public class SnapshotService {
|
|
|
public static final String DEFAULT_CURRENCY = "USD";
|
|
public static final String DEFAULT_CURRENCY = "USD";
|
|
|
|
|
|
|
|
@Scheduled(cron = ONCE_PER_MONTH)
|
|
@Scheduled(cron = ONCE_PER_MONTH)
|
|
|
|
|
+ @SchedulerLock(name = "SnapshotService_createSnapshots", lockAtLeastFor = "PT2M", lockAtMostFor = "PT10M")
|
|
|
public void createSnapshots() {
|
|
public void createSnapshots() {
|
|
|
List<Portfolio> portfolios = service.getAllIds().stream()
|
|
List<Portfolio> portfolios = service.getAllIds().stream()
|
|
|
.map(portfolioId -> service.get(portfolioId, DEFAULT_CURRENCY))
|
|
.map(portfolioId -> service.get(portfolioId, DEFAULT_CURRENCY))
|