34 lines
969 B
Java
34 lines
969 B
Java
package com.accounting.schedule;
|
|
|
|
import com.accounting.service.GoldPriceService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@Slf4j
|
|
@Component
|
|
@RequiredArgsConstructor
|
|
public class GoldPriceScheduler {
|
|
|
|
private static final String DEFAULT_GOLD_ID = "1053";
|
|
|
|
private final GoldPriceService goldPriceService;
|
|
|
|
@Scheduled(cron = "0 */15 * * * ?", zone = "Asia/Shanghai")
|
|
public void fetchPeriodicPrice() {
|
|
runJob("periodic");
|
|
}
|
|
|
|
private void runJob(String tag) {
|
|
try {
|
|
log.info("Gold price scheduled job [{}] start", tag);
|
|
goldPriceService.refreshCurrentPrice(DEFAULT_GOLD_ID);
|
|
log.info("Gold price scheduled job [{}] success", tag);
|
|
} catch (Exception e) {
|
|
log.error("Gold price scheduled job [{}] failed", tag, e);
|
|
}
|
|
}
|
|
}
|
|
|