xxljob 配置具体定时任务_分布式任务调度: XXL-Job
生活随笔
收集整理的這篇文章主要介紹了
xxljob 配置具体定时任务_分布式任务调度: XXL-Job
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 任務調度中心搭建、部署、任務管理與監控[1]
任務調度中心頁面2 SpringBoot 集成 xxl-job:創建調度任務
maven項目pom.xml引入依賴:
<dependency><groupId>com.xuxueli</groupId><artifactId>xxl-job-core</artifactId><version>2.2.0</version> </dependency>application.properties配置
### xxl-job 任務調度管理中心:web地址 #xxl.job.admin.addresses=http://192.168.4.20:8081/xxl-job-admin ### xxl-job 任務調度管理中心:登錄用戶名密碼 xxl.job.login.username=admin xxl.job.login.password=123456 ### xxl-job 任務調度管理中心:通訊TOKEN,非空時啟用 xxl.job.accessToken= ### xxl-job 任務調度管理中心:國際化設置,默認為中文版本,值設置為“en”時切換為英文版本 xxl-job, i18n (default empty as chinese, "en" as english) xxl.job.i18n=### xxl-job 執行期配置 xxl.job.executor.appname=xxl-job ### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null xxl.job.executor.address= ### xxl-job executor server-info xxl.job.executor.ip= xxl.job.executor.port=-1 ### xxl-job executor log-path xxl.job.executor.logpath=/XApp/logs/xxl-job/jobhandler ### xxl-job executor log-retention-days xxl.job.executor.logretentiondays=30Java配置文件:
package org.lyy.job.config;import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;//import org.slf4j.Logger; //import org.slf4j.LoggerFactory; import lombok.extern.slf4j.Slf4j;/*** Description: xxl-job 配置類 <br/>* author: lyy <br/>* version: 1.0*/ @Slf4j @Configuration public class XxlJobConfig {//private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);@Value("${xxl.job.admin.addresses}")private String adminAddresses;@Value("${xxl.job.accessToken}")private String accessToken;@Value("${xxl.job.executor.appname}")private String appname;@Value("${xxl.job.executor.address}")private String address;@Value("${xxl.job.executor.ip}")private String ip;@Value("${xxl.job.executor.port}")private int port;@Value("${xxl.job.executor.logpath}")private String logPath;@Value("${xxl.job.executor.logretentiondays}")private int logRetentionDays;@Beanpublic XxlJobSpringExecutor xxlJobExecutor() {logger.info("xxl-job config init ======>");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppname(appname);xxlJobSpringExecutor.setAddress(address);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;} }調度中心定義調度任務
代碼編寫調度任務
package org.lyy.job.handler;import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Component;import com.lyy.base.util.StringUtils; import com.lyy.data.rpc.service.RpcStuService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob;import lombok.extern.slf4j.Slf4j; /*** * 學情數據任務* 定時編輯工具:https://www.matools.com/cron/* @author lyy*/ @Slf4j @Component public class StuDataJob {private final SimpleDateFormat DATA_FORMAT = new SimpleDateFormat("yyyy-MM-dd ");@Reference(version = "${service.version}")private RpcStuService rpcStuService;/*** 每天 00:00:01 執行一次* @param date* @return* @throws Exception*/@XxlJob("stuJobHandler")public ReturnT<String> stuJobHandler(String date) throws Exception {log.info("enter:{}", date);Date filterDate;if (StringUtils.isNotEmpty(date)) {filterDate = DATA_FORMAT.parse(date);} else {Calendar cal = Calendar.getInstance();cal.add(Calendar.DATE, -1);filterDate = cal.getTime();}log.info("filterDate={}", DATA_FORMAT.format(filterDate));boolean flag = rpcStuService.batchSaveStuQuesOfDay(filterDate);log.info("return:{}", flag);return flag? ReturnT.SUCCESS : ReturnT.FAIL;} }參考
總結
以上是生活随笔為你收集整理的xxljob 配置具体定时任务_分布式任务调度: XXL-Job的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 内核重定位,Linux 内核
- 下一篇: PHP定时抽奖怎么实现的,PHP 实现抽