From 5ec681e7af9c6f014d452f69e9a9c5a1c85c0e56 Mon Sep 17 00:00:00 2001 From: gitdq1016 <31494286+gitdq1016@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:15:02 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9xxljob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 + .../dl/officialsite/bounty/BountyService.java | 7 +- .../officialsite/bounty/job/BountyXxlJob.java | 29 ++++++ .../dl/officialsite/config/XxlJobConfig.java | 37 ++++++++ .../officialsite/config/XxlJobProperties.java | 95 +++++++++++++++++++ .../com/dl/officialsite/defi/Schedule.java | 8 +- .../dl/officialsite/defi/job/DefiXxlJob.java | 84 ++++++++++++++++ .../defi/service/AaveTokenAPYService.java | 8 +- .../defi/service/WhaleService.java | 11 ++- .../distributor/DistributeService.java | 7 +- .../distributor/job/DistributorXxlJob.java | 31 ++++++ .../redpacket/RedPacketService.java | 8 +- .../redpacket/job/RedPacketXxlJob.java | 30 ++++++ src/main/resources/application.yml | 13 ++- 14 files changed, 357 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/dl/officialsite/bounty/job/BountyXxlJob.java create mode 100644 src/main/java/com/dl/officialsite/config/XxlJobConfig.java create mode 100644 src/main/java/com/dl/officialsite/config/XxlJobProperties.java create mode 100644 src/main/java/com/dl/officialsite/defi/job/DefiXxlJob.java create mode 100644 src/main/java/com/dl/officialsite/distributor/job/DistributorXxlJob.java create mode 100644 src/main/java/com/dl/officialsite/redpacket/job/RedPacketXxlJob.java diff --git a/build.gradle b/build.gradle index ddc9ff44..981a7734 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ dependencies{ // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0' + implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16' implementation 'mysql:mysql-connector-java:8.0.28' @@ -63,6 +64,7 @@ dependencies{ implementation 'io.springfox:springfox-boot-starter:3.0.0' implementation 'com.qcloud:cos_api:5.6.155' implementation 'org.springframework.social:spring-social-twitter:1.1.2.RELEASE' + implementation("com.xuxueli:xxl-job-core:2.4.1") //graphql // implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release")) diff --git a/src/main/java/com/dl/officialsite/bounty/BountyService.java b/src/main/java/com/dl/officialsite/bounty/BountyService.java index c9566b28..d60393e2 100644 --- a/src/main/java/com/dl/officialsite/bounty/BountyService.java +++ b/src/main/java/com/dl/officialsite/bounty/BountyService.java @@ -24,6 +24,8 @@ import java.util.stream.Collectors; import javax.persistence.criteria.Predicate; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -65,10 +67,11 @@ public BountyService(BountyRepository bountyRepository, - @Scheduled(cron = "${jobs.bounty.corn:0 0 * * * *}") - @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) +// @Scheduled(cron = "${jobs.bounty.corn:0 0 * * * *}") +// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateBountyData() { log.info("updateBountyData_schedule task begin --------------------- "); + XxlJobHelper.log("updateBountyData_schedule task begin --------------------- "); //update status long currentSeconds = System.currentTimeMillis() / 1000; List bountyList = bountyRepository.findAll( diff --git a/src/main/java/com/dl/officialsite/bounty/job/BountyXxlJob.java b/src/main/java/com/dl/officialsite/bounty/job/BountyXxlJob.java new file mode 100644 index 00000000..bbc55bbc --- /dev/null +++ b/src/main/java/com/dl/officialsite/bounty/job/BountyXxlJob.java @@ -0,0 +1,29 @@ +package com.dl.officialsite.bounty.job; + +import com.dl.officialsite.bounty.BountyService; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author xiaoming + * @Date 2024/7/6 7:45 PM + **/ +@Component +public class BountyXxlJob { + + @Autowired + private BountyService bountyService; + + /** + * 更新bounty数据 + */ + @XxlJob("updateBountyDataJobHandler") + public void updateBountyStatus() { + XxlJobHelper.log("updateBountyData start"); + bountyService.updateBountyData(); + XxlJobHelper.log("updateBountyData end"); + } +} diff --git a/src/main/java/com/dl/officialsite/config/XxlJobConfig.java b/src/main/java/com/dl/officialsite/config/XxlJobConfig.java new file mode 100644 index 00000000..a5b985f8 --- /dev/null +++ b/src/main/java/com/dl/officialsite/config/XxlJobConfig.java @@ -0,0 +1,37 @@ +package com.dl.officialsite.config; + +import com.xxl.job.core.executor.XxlJobExecutor; +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Description + * @Author xiaoming + * @Date 2024/7/5 10:07 PM + **/ +@Configuration +@Slf4j +@EnableConfigurationProperties({XxlJobProperties.class}) +public class XxlJobConfig { + + @Bean + public XxlJobExecutor xxlJobExecutor(XxlJobProperties properties) { + log.info("[xxlJobExecutor][初始化 XXL-Job 执行器的配置]"); + XxlJobProperties.AdminProperties admin = properties.getAdmin(); + XxlJobProperties.ExecutorProperties executor = properties.getExecutor(); + + // 初始化执行器 + XxlJobExecutor xxlJobExecutor = new XxlJobSpringExecutor(); + xxlJobExecutor.setIp(executor.getIp()); + xxlJobExecutor.setPort(executor.getPort()); + xxlJobExecutor.setAppname(executor.getAppName()); + xxlJobExecutor.setLogPath(executor.getLogPath()); + xxlJobExecutor.setLogRetentionDays(executor.getLogRetentionDays()); + xxlJobExecutor.setAdminAddresses(admin.getAddresses()); + xxlJobExecutor.setAccessToken(properties.getAccessToken()); + return xxlJobExecutor; + } +} diff --git a/src/main/java/com/dl/officialsite/config/XxlJobProperties.java b/src/main/java/com/dl/officialsite/config/XxlJobProperties.java new file mode 100644 index 00000000..c0ebef97 --- /dev/null +++ b/src/main/java/com/dl/officialsite/config/XxlJobProperties.java @@ -0,0 +1,95 @@ +package com.dl.officialsite.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * XXL-Job 配置类 + */ +@ConfigurationProperties("xxl.job") +@Validated +@Data +public class XxlJobProperties { + + /** + * 访问令牌 + */ + private String accessToken; + /** + * 控制器配置 + */ + @NotNull(message = "控制器配置不能为空") + private AdminProperties admin; + /** + * 执行器配置 + */ + @NotNull(message = "执行器配置不能为空") + private ExecutorProperties executor; + + /** + * XXL-Job 调度器配置类 + */ + @Data + @Valid + public static class AdminProperties { + + /** + * 调度器地址 + */ + @NotEmpty(message = "调度器地址不能为空") + private String addresses; + + } + + /** + * XXL-Job 执行器配置类 + */ + @Data + @Valid + public static class ExecutorProperties { + + /** + * 默认端口 + * + * 这里使用 -1 表示随机 + */ + private static final Integer PORT_DEFAULT = -1; + + /** + * 默认日志保留天数 + * + * 如果想永久保留,则设置为 -1 + */ + private static final Integer LOG_RETENTION_DAYS_DEFAULT = 30; + + /** + * 应用名 + */ + @NotEmpty(message = "应用名不能为空") + private String appName; + /** + * 执行器的 IP + */ + private String ip; + /** + * 执行器的 Port + */ + private Integer port = PORT_DEFAULT; + /** + * 日志地址 + */ + @NotEmpty(message = "日志地址不能为空") + private String logPath; + /** + * 日志保留天数 + */ + private Integer logRetentionDays = LOG_RETENTION_DAYS_DEFAULT; + + } + +} diff --git a/src/main/java/com/dl/officialsite/defi/Schedule.java b/src/main/java/com/dl/officialsite/defi/Schedule.java index 9aa53381..7be49096 100644 --- a/src/main/java/com/dl/officialsite/defi/Schedule.java +++ b/src/main/java/com/dl/officialsite/defi/Schedule.java @@ -9,6 +9,8 @@ import com.dl.officialsite.team.vo.TeamsWithMembers; import java.math.BigDecimal; import java.util.List; + +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -38,7 +40,7 @@ public class Schedule { /** * 监控价格一天发送一次 */ - @Scheduled(cron = "0 0 12 * * ?") +// @Scheduled(cron = "0 0 12 * * ?") public void monitorPrice() throws Exception { log.info("monitorPrice start"); //查找team0 memeber获取地址 @@ -60,10 +62,11 @@ public void monitorPrice() throws Exception { /** * 监控健康系数,如果小于1.2,立即发送邮件 */ - @Scheduled(cron = "0 0/30 * * * ? ") +// @Scheduled(cron = "0 0/30 * * * ? ") public void monitorHealth() { try { log.info("monitorHealth start"); + XxlJobHelper.log("monitorHealth start"); //查找team0 memeber获取地址 TeamQueryVo teamQueryVo = new TeamQueryVo(); teamQueryVo.setTeamName("Dapp-Learning DAO core founders"); @@ -86,6 +89,7 @@ public void monitorHealth() { } } catch (Exception e) { log.error("monitorHealth error", e); + XxlJobHelper.log("monitorHealth error", e); } } diff --git a/src/main/java/com/dl/officialsite/defi/job/DefiXxlJob.java b/src/main/java/com/dl/officialsite/defi/job/DefiXxlJob.java new file mode 100644 index 00000000..6bdfc37a --- /dev/null +++ b/src/main/java/com/dl/officialsite/defi/job/DefiXxlJob.java @@ -0,0 +1,84 @@ +package com.dl.officialsite.defi.job; + +import com.dl.officialsite.defi.Schedule; +import com.dl.officialsite.defi.TokenInfoList; +import com.dl.officialsite.defi.service.AaveService; +import com.dl.officialsite.defi.service.AaveTokenAPYService; +import com.dl.officialsite.defi.service.WhaleService; +import com.dl.officialsite.defi.vo.HealthInfoVo; +import com.dl.officialsite.mail.EmailService; +import com.dl.officialsite.member.Member; +import com.dl.officialsite.team.TeamService; +import com.dl.officialsite.team.vo.TeamQueryVo; +import com.dl.officialsite.team.vo.TeamsWithMembers; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @Description + * @Author xiaoming + * @Date 2024/7/6 7:02 PM + **/ +@Component +@Slf4j +public class DefiXxlJob { + + @Autowired + private Schedule schedule; + + @Autowired + private AaveTokenAPYService aaveTokenAPYService; + + @Autowired + private WhaleService whaleService; + + + /** + * 监控价格一天发送一次 + */ + @XxlJob("monitorPriceJobHandler") + public void monitorPrice() throws Exception { + XxlJobHelper.log("monitorPrice start"); + schedule.monitorPrice(); + XxlJobHelper.log("monitorPrice end"); + } + + /** + * 监控健康系数,如果小于1.2,立即发送邮件 + */ + @XxlJob("monitorHealthJobHandler") + public void monitorHealth() { + XxlJobHelper.log("monitorHealth start"); + schedule.monitorHealth(); + XxlJobHelper.log("monitorHealth end"); + } + + + /** + * 定期更新 Token 的 APY(年化收益率)信息 + */ + @XxlJob("updateTokenAPYInfoJobHandler") + public void updateTokenAPYInfo() { + XxlJobHelper.log("update token info task begin --------------------- "); + aaveTokenAPYService.updateTokenAPYInfo(); + XxlJobHelper.log("update token info task end --------------------- "); + } + + /** + * 更新Whale和WhaleTxRow数据 + */ + @XxlJob("aaveListenerJobHandler") + public void aaveListener() { + XxlJobHelper.log("aaveListenerJobHandler start"); + whaleService.aaveListener(); + XxlJobHelper.log("aaveListenerJobHandler end"); + } + +} diff --git a/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java b/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java index 319ac9ca..54695692 100644 --- a/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java +++ b/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java @@ -21,6 +21,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; + +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Scheduled; @@ -131,12 +133,14 @@ public List queryChainList() { return new ArrayList<>(Web3jAutoConfiguration.web3jMap.keySet()); } - @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") - @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) +// @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") +// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateTokenAPYInfo() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); log.info("update token info task begin --------------------- "); + XxlJobHelper.log("update token info task begin --------------------- "); log.info("now date {}", LocalDateTime.now().format(formatter)); + XxlJobHelper.log("now date {}", LocalDateTime.now().format(formatter)); List tokenAPYInfoList = queryTokenApyOnChain(); tokenAPYInfoRepository.deleteAll(); tokenAPYInfoRepository.saveAll(tokenAPYInfoList); diff --git a/src/main/java/com/dl/officialsite/defi/service/WhaleService.java b/src/main/java/com/dl/officialsite/defi/service/WhaleService.java index 1ba7f8c3..53e29c3a 100644 --- a/src/main/java/com/dl/officialsite/defi/service/WhaleService.java +++ b/src/main/java/com/dl/officialsite/defi/service/WhaleService.java @@ -27,6 +27,8 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; + +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -86,8 +88,8 @@ public WhaleService(WhaleRepository whaleRepository, WhaleTxRowRepository whaleT this.whaleChainTokenRepository = whaleChainTokenRepository; } - @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") - @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) +// @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") +// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void aaveListener() { List whaleList = new ArrayList<>(); List insertWhaleTxRowList = new ArrayList<>(); @@ -102,6 +104,7 @@ public void aaveListener() { String jsonStr = requestAaveGraph(100, 0); JSONObject jsonObject = JSONUtil.parseObj(jsonStr); if (jsonObject.toString().contains("error")) { + XxlJobHelper.log("解析aave的graph失败"); throw new RuntimeException("解析aave的graph失败"); } JSONObject data = jsonObject.getJSONObject("data"); @@ -134,8 +137,11 @@ public void aaveListener() { public void insertWhaleAndTx(List whaleList, List whaleTxRowList) { log.info("开始插入数据"); + XxlJobHelper.log("开始插入数据"); log.info("whaleList.size() = {}-------------------", whaleList.size()); + XxlJobHelper.log("whaleList.size() = {}-------------------", whaleList.size()); log.info("whaleTxRowList.size() = {}-------------------", whaleTxRowList.size()); + XxlJobHelper.log("whaleTxRowList.size() = {}-------------------", whaleTxRowList.size()); if (!whaleList.isEmpty()) { batchRepository.batchInsert(whaleList); } @@ -156,6 +162,7 @@ public void insertWhaleAndTx(List whaleList, List whaleTxRowL } } log.info("插入数据结束"); + XxlJobHelper.log("插入数据结束"); } private Long getOneYearBefore() { diff --git a/src/main/java/com/dl/officialsite/distributor/DistributeService.java b/src/main/java/com/dl/officialsite/distributor/DistributeService.java index 78f018ff..322adaa5 100644 --- a/src/main/java/com/dl/officialsite/distributor/DistributeService.java +++ b/src/main/java/com/dl/officialsite/distributor/DistributeService.java @@ -24,6 +24,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; @@ -100,16 +101,18 @@ public class DistributeService { @Autowired private ConstantConfig constantConfig; - @Scheduled(cron = "${jobs.distribute.corn:0/10 * * * * ?}") - @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) +// @Scheduled(cron = "${jobs.distribute.corn:0/10 * * * * ?}") +// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateDistributeStatus() { log.info("schedule task begin --------------------- "); + XxlJobHelper.log("DistributeService updateDistributeStatus start"); for (String chainId : chainConfig.getIds()) { try { updateDistributeStatusByChainId(chainId); } catch (Exception e) { e.printStackTrace(); log.error("updateDistributeStatusByChainId: " + chainId + " error:" + e.getMessage()); + XxlJobHelper.log("updateDistributeStatusByChainId: " + chainId + " error:" + e.getMessage()); } } } diff --git a/src/main/java/com/dl/officialsite/distributor/job/DistributorXxlJob.java b/src/main/java/com/dl/officialsite/distributor/job/DistributorXxlJob.java new file mode 100644 index 00000000..cb4d7064 --- /dev/null +++ b/src/main/java/com/dl/officialsite/distributor/job/DistributorXxlJob.java @@ -0,0 +1,31 @@ +package com.dl.officialsite.distributor.job; + +import com.dl.officialsite.distributor.DistributeService; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author xiaoming + * @Date 2024/7/6 7:40 PM + **/ +@Component +@Slf4j +public class DistributorXxlJob { + + @Autowired + private DistributeService distributeService; + + /** + * 更新链上状态 + */ + @XxlJob("updateDistributeStatusJobHandler") + public void updateDistributeStatus() { + XxlJobHelper.log("updateDistributeStatus start"); + distributeService.updateDistributeStatus(); + XxlJobHelper.log("updateDistributeStatus end"); + } +} diff --git a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java index e15a472e..a2527637 100644 --- a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java +++ b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java @@ -6,6 +6,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -43,16 +44,18 @@ public class RedPacketService { public CloseableHttpClient httpClient = HttpClients.createDefault(); - @Scheduled(cron = "${jobs.redpacket.corn:0/10 * * * * ?}") - @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) +// @Scheduled(cron = "${jobs.redpacket.corn:0/10 * * * * ?}") +// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateRedpacketStatus() { log.info("schedule task begin --------------------- "); + XxlJobHelper.log("RedPacketService updateRedPacketStatus start"); for (String chainId : chainConfig.getIds()) { try { updateRedpacketStatusByChainId(chainId); } catch (Exception e) { e.printStackTrace(); log.error("updateRedpacketStatusByChainId: " + chainId + " error:" + e.getMessage()); + XxlJobHelper.log("updateRedPacketStatusByChainId: " + chainId + " error:" + e.getMessage()); } } } @@ -64,6 +67,7 @@ private void updateRedpacketStatusByChainId(String chainId) throws IOException { if (jsonResponse.contains("errors")) { log.info("response from the graph: chainId{}, data {} ", chainId, jsonResponse); + XxlJobHelper.log("response from the graph: chainId{}, data {} ", chainId, jsonResponse); return; } JsonObject jsonObject = JsonParser.parseString(jsonResponse).getAsJsonObject(); diff --git a/src/main/java/com/dl/officialsite/redpacket/job/RedPacketXxlJob.java b/src/main/java/com/dl/officialsite/redpacket/job/RedPacketXxlJob.java new file mode 100644 index 00000000..32479f83 --- /dev/null +++ b/src/main/java/com/dl/officialsite/redpacket/job/RedPacketXxlJob.java @@ -0,0 +1,30 @@ +package com.dl.officialsite.redpacket.job; + +import com.dl.officialsite.redpacket.RedPacketService; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author xiaoming + * @Date 2024/7/6 7:26 PM + **/ +@Component +public class RedPacketXxlJob { + + @Autowired + private RedPacketService redPacketService; + + + /** + * 更新红包状态 + */ + @XxlJob("updateRedPacketStatusJobHandler") + public void updateRedPacketStatus() { + XxlJobHelper.log("updateRedPacketStatus start"); + redPacketService.updateRedpacketStatus(); + XxlJobHelper.log("updateRedPacketStatus end"); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 89df6507..1d5529e3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -121,4 +121,15 @@ debank: protocolList: https://pro-openapi.debank.com/v1/user/all_simple_protocol_list userTokenList: https://pro-openapi.debank.com/v1/user/all_token_list totalBalance: https://pro-openapi.debank.com/v1/user/total_balance - key: \ No newline at end of file + key: + +#xxl-job config +xxl: + job: + admin: + addresses: http://127.0.0.1:8087/xxl-job-admin + accessToken: ${XXL_JOB_TOKEN} + executor: + appName: websit-backend + port: 9998 + log-path: /Users/apple/workSpace/dapp-learning/mybackend/logs/ #todo 更换 \ No newline at end of file From 000d8ea1dfd4cd5ebf1956168af80b0a5ab79d82 Mon Sep 17 00:00:00 2001 From: xiaoming <31494286+gitdq1016@users.noreply.github.com> Date: Sun, 21 Jul 2024 17:52:36 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9xxljob=20admin=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1d5529e3..29835296 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -127,9 +127,9 @@ debank: xxl: job: admin: - addresses: http://127.0.0.1:8087/xxl-job-admin + addresses: http://${XXL_JOB_TOKEN}/xxl-job-admin accessToken: ${XXL_JOB_TOKEN} executor: appName: websit-backend port: 9998 - log-path: /Users/apple/workSpace/dapp-learning/mybackend/logs/ #todo 更换 \ No newline at end of file + log-path: /logs/executor/ #todo 更换 \ No newline at end of file From 57deda7b4f2de346f93db30096479f12330878f5 Mon Sep 17 00:00:00 2001 From: xiaoming <31494286+gitdq1016@users.noreply.github.com> Date: Sun, 21 Jul 2024 17:57:02 +0800 Subject: [PATCH 3/6] add log path --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 29835296..dc74b5b5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -132,4 +132,4 @@ xxl: executor: appName: websit-backend port: 9998 - log-path: /logs/executor/ #todo 更换 \ No newline at end of file + log-path: ${XXL_JOB_EXECUTOR_lOG_PATH} # executor log path \ No newline at end of file From 1940f47a10ed2a46efac4de71b5d1fd54b2cf497 Mon Sep 17 00:00:00 2001 From: xiaoming <31494286+gitdq1016@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:12:28 +0800 Subject: [PATCH 4/6] modify yaml --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index dc74b5b5..92cba88d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -127,7 +127,7 @@ debank: xxl: job: admin: - addresses: http://${XXL_JOB_TOKEN}/xxl-job-admin + addresses: http://${XXL_JOB_ADMIN_HOST}/xxl-job-admin accessToken: ${XXL_JOB_TOKEN} executor: appName: websit-backend From bf9412ccb7876b14c3f20e201469d6c6277be617 Mon Sep 17 00:00:00 2001 From: xiaoming <31494286+gitdq1016@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:39:29 +0800 Subject: [PATCH 5/6] remove comment --- src/main/java/com/dl/officialsite/bounty/BountyService.java | 2 -- src/main/java/com/dl/officialsite/defi/Schedule.java | 2 -- .../com/dl/officialsite/defi/service/AaveTokenAPYService.java | 2 -- .../java/com/dl/officialsite/defi/service/WhaleService.java | 2 -- .../java/com/dl/officialsite/distributor/DistributeService.java | 2 -- .../java/com/dl/officialsite/redpacket/RedPacketService.java | 2 -- 6 files changed, 12 deletions(-) diff --git a/src/main/java/com/dl/officialsite/bounty/BountyService.java b/src/main/java/com/dl/officialsite/bounty/BountyService.java index 81cd855f..1cd6f30a 100644 --- a/src/main/java/com/dl/officialsite/bounty/BountyService.java +++ b/src/main/java/com/dl/officialsite/bounty/BountyService.java @@ -70,8 +70,6 @@ public BountyService(BountyRepository bountyRepository, -// @Scheduled(cron = "${jobs.bounty.corn:0 0 * * * *}") -// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateBountyData() { log.info("updateBountyData_schedule task begin --------------------- "); XxlJobHelper.log("updateBountyData_schedule task begin --------------------- "); diff --git a/src/main/java/com/dl/officialsite/defi/Schedule.java b/src/main/java/com/dl/officialsite/defi/Schedule.java index 7be49096..1ba33b7a 100644 --- a/src/main/java/com/dl/officialsite/defi/Schedule.java +++ b/src/main/java/com/dl/officialsite/defi/Schedule.java @@ -40,7 +40,6 @@ public class Schedule { /** * 监控价格一天发送一次 */ -// @Scheduled(cron = "0 0 12 * * ?") public void monitorPrice() throws Exception { log.info("monitorPrice start"); //查找team0 memeber获取地址 @@ -62,7 +61,6 @@ public void monitorPrice() throws Exception { /** * 监控健康系数,如果小于1.2,立即发送邮件 */ -// @Scheduled(cron = "0 0/30 * * * ? ") public void monitorHealth() { try { log.info("monitorHealth start"); diff --git a/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java b/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java index 54695692..2e89f237 100644 --- a/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java +++ b/src/main/java/com/dl/officialsite/defi/service/AaveTokenAPYService.java @@ -133,8 +133,6 @@ public List queryChainList() { return new ArrayList<>(Web3jAutoConfiguration.web3jMap.keySet()); } -// @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") -// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateTokenAPYInfo() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); log.info("update token info task begin --------------------- "); diff --git a/src/main/java/com/dl/officialsite/defi/service/WhaleService.java b/src/main/java/com/dl/officialsite/defi/service/WhaleService.java index 53e29c3a..a07b7c9b 100644 --- a/src/main/java/com/dl/officialsite/defi/service/WhaleService.java +++ b/src/main/java/com/dl/officialsite/defi/service/WhaleService.java @@ -88,8 +88,6 @@ public WhaleService(WhaleRepository whaleRepository, WhaleTxRowRepository whaleT this.whaleChainTokenRepository = whaleChainTokenRepository; } -// @Scheduled(cron = "${jobs.defi.corn: 0 30 * * * * ?}") -// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void aaveListener() { List whaleList = new ArrayList<>(); List insertWhaleTxRowList = new ArrayList<>(); diff --git a/src/main/java/com/dl/officialsite/distributor/DistributeService.java b/src/main/java/com/dl/officialsite/distributor/DistributeService.java index c79ec0cf..3ff7ec92 100644 --- a/src/main/java/com/dl/officialsite/distributor/DistributeService.java +++ b/src/main/java/com/dl/officialsite/distributor/DistributeService.java @@ -105,8 +105,6 @@ public class DistributeService { @Resource private MerkleDistributorConfig merkleDistributorConfig; -// @Scheduled(cron = "${jobs.distribute.corn:0/30 * * * * ?}") -// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateDistributeStatus() { log.info("schedule task begin --------------------- "); XxlJobHelper.log("DistributeService updateDistributeStatus start"); diff --git a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java index 723ad3d6..c0c17787 100644 --- a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java +++ b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java @@ -48,8 +48,6 @@ public class RedPacketService { public CloseableHttpClient httpClient = HttpClients.createDefault(); -// @Scheduled(cron = "${jobs.redpacket.corn:0/30 * * * * ?}") -// @ConditionalOnProperty(name = "scheduler.enabled", havingValue = "true", matchIfMissing = true) public void updateRedpacketStatus() { log.info("schedule task begin --------------------- "); XxlJobHelper.log("RedPacketService updateRedPacketStatus start"); From 38f47a07d9b988612de8b9fdcb1aef3873651f86 Mon Sep 17 00:00:00 2001 From: xiaoming <31494286+gitdq1016@users.noreply.github.com> Date: Sun, 28 Jul 2024 20:30:54 +0800 Subject: [PATCH 6/6] remove some log --- src/main/java/com/dl/officialsite/bounty/BountyService.java | 1 - src/main/java/com/dl/officialsite/defi/Schedule.java | 2 -- .../com/dl/officialsite/distributor/DistributeService.java | 3 --- .../java/com/dl/officialsite/redpacket/RedPacketService.java | 4 ---- 4 files changed, 10 deletions(-) diff --git a/src/main/java/com/dl/officialsite/bounty/BountyService.java b/src/main/java/com/dl/officialsite/bounty/BountyService.java index 1cd6f30a..de3bb91a 100644 --- a/src/main/java/com/dl/officialsite/bounty/BountyService.java +++ b/src/main/java/com/dl/officialsite/bounty/BountyService.java @@ -71,7 +71,6 @@ public BountyService(BountyRepository bountyRepository, public void updateBountyData() { - log.info("updateBountyData_schedule task begin --------------------- "); XxlJobHelper.log("updateBountyData_schedule task begin --------------------- "); //update status long currentSeconds = System.currentTimeMillis() / 1000; diff --git a/src/main/java/com/dl/officialsite/defi/Schedule.java b/src/main/java/com/dl/officialsite/defi/Schedule.java index 1ba33b7a..e1c8dc67 100644 --- a/src/main/java/com/dl/officialsite/defi/Schedule.java +++ b/src/main/java/com/dl/officialsite/defi/Schedule.java @@ -63,7 +63,6 @@ public void monitorPrice() throws Exception { */ public void monitorHealth() { try { - log.info("monitorHealth start"); XxlJobHelper.log("monitorHealth start"); //查找team0 memeber获取地址 TeamQueryVo teamQueryVo = new TeamQueryVo(); @@ -86,7 +85,6 @@ public void monitorHealth() { } } } catch (Exception e) { - log.error("monitorHealth error", e); XxlJobHelper.log("monitorHealth error", e); } } diff --git a/src/main/java/com/dl/officialsite/distributor/DistributeService.java b/src/main/java/com/dl/officialsite/distributor/DistributeService.java index 3ff7ec92..034e0e78 100644 --- a/src/main/java/com/dl/officialsite/distributor/DistributeService.java +++ b/src/main/java/com/dl/officialsite/distributor/DistributeService.java @@ -106,14 +106,11 @@ public class DistributeService { private MerkleDistributorConfig merkleDistributorConfig; public void updateDistributeStatus() { - log.info("schedule task begin --------------------- "); XxlJobHelper.log("DistributeService updateDistributeStatus start"); for (String chainId : chainConfig.getIds()) { try { updateDistributeStatusByChainId(chainId); } catch (Exception e) { - e.printStackTrace(); - log.error("updateDistributeStatusByChainId: " + chainId + " error:" + e.getMessage()); XxlJobHelper.log("updateDistributeStatusByChainId: " + chainId + " error:" + e.getMessage()); } } diff --git a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java index c0c17787..7c2caa09 100644 --- a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java +++ b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java @@ -49,14 +49,11 @@ public class RedPacketService { public CloseableHttpClient httpClient = HttpClients.createDefault(); public void updateRedpacketStatus() { - log.info("schedule task begin --------------------- "); XxlJobHelper.log("RedPacketService updateRedPacketStatus start"); for (String chainId : chainConfig.getIds()) { try { updateRedpacketStatusByChainId(chainId); } catch (Exception e) { - e.printStackTrace(); - log.error("updateRedpacketStatusByChainId: " + chainId + " error:" + e.getMessage()); XxlJobHelper.log("updateRedPacketStatusByChainId: " + chainId + " error:" + e.getMessage()); } } @@ -68,7 +65,6 @@ private void updateRedpacketStatusByChainId(String chainId) throws IOException { String jsonResponse = EntityUtils.toString(entity); if (jsonResponse.contains("errors")) { - log.info("response from the graph: chainId{}, data {} ", chainId, jsonResponse); XxlJobHelper.log("response from the graph: chainId{}, data {} ", chainId, jsonResponse); return; }