This commit is contained in:
VoGiaHuy2058
2025-05-12 18:44:16 +07:00
parent 59684cccfc
commit 85094c22b2
3 changed files with 87 additions and 74 deletions

View File

@@ -2,6 +2,7 @@ package cn.stock.market.infrastructure.job;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -12,21 +13,29 @@ import cn.stock.market.domain.basic.service.SiteArticleService;
import cn.stock.market.domain.basic.service.SiteNewsService;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct;
@Slf4j
//@Component
@Component
public class JobBoot {
@Autowired
private SiteNewsService siteNewsService;
@Autowired
private SiteArticleService siteArticleService;
/**
* cronExpression表达式定义 
字段   允许值   允许的特殊字符
  0-59   , - * /
  0-59   , - * /
小时   0-23   , - * /
日期   1-31   , - * ? / L W C
月份   1-12 或者 JAN-DEC   , - * /
星期   1-7 或者 SUN-SAT   , - * ? / L C #
年(可选)   留空, 1970-2099   , - * /
https://blog.csdn.net/ClementAD/article/details/42042111
字段   允许值   允许的特殊字符
  0-59   , - * /
  0-59   , - * /
小时   0-23   , - * /
日期   1-31   , - * ? / L W C
月份   1-12 或者 JAN-DEC   , - * /
星期   1-7 或者 SUN-SAT   , - * ? / L C #
年(可选)   留空, 1970-2099   , - * /
https://blog.csdn.net/ClementAD/article/details/42042111
*/
// @Scheduled(cron="0 0/1 * * * ? ")
@Scheduled(cron="0/30 * * * * ? ")
@@ -35,33 +44,33 @@ public class JobBoot {
// Stopwatch stopwatch = Stopwatch.createStarted();
// log.info("batchStockTrust执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
@Scheduled(cron="0/30 * * * * ? ")
public void batchStockPosition() {
MdcUtil.setTraceIdIfAbsent();
// Stopwatch stopwatch = Stopwatch.createStarted();
// log.info("batchStockPosition执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
/*
* 新闻资讯抓取
* */
/*
* 新闻资讯抓取
* */
@Scheduled(cron = "0 0/30 9-20 * * ?")
public void artInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = SiteArticleService.of().grabArticle();
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
/*
* 新闻资讯抓取
* */
@Scheduled(cron = "0 0/30 9-20 * * ?")
public void newsInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = SiteNewsService.of().grabNews();
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
public void artInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = siteArticleService.grabArticle();
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
/*
* 新闻资讯抓取
* */
@Scheduled(cron = "0 0/30 9-20 * * ?")
public void newsInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = siteNewsService.grabNews();
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
}