Commit d1487b51 authored by zhangyong's avatar zhangyong

1

parent d17d6fe2
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <!-- <dependency> https://blog.csdn.net/liuxiaochang_2011/article/details/80663093
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency> -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
......
package com.egolm.jobs.config.schedule; package com.egolm.jobs.config.schedule;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
public class JobCommon { public class JobCommon implements Serializable {
private static final long serialVersionUID = 1L;
private String sJobID; private String sJobID;
private Integer nRunFlg; private Integer nRunFlg;
private String sCronExpression; private String sCronExpression;
......
...@@ -4,23 +4,23 @@ import org.quartz.JobExecutionContext; ...@@ -4,23 +4,23 @@ import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.scheduling.quartz.QuartzJobBean;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.jobs.JobsApplication;
import com.egolm.jobs.service.JobService; import com.egolm.jobs.service.JobService;
public class ScheduleJob extends QuartzJobBean { public class ScheduleJob extends QuartzJobBean {
private static final Logger logger = LoggerFactory.getLogger(ScheduleJob.class); private static final Logger logger = LoggerFactory.getLogger(ScheduleJob.class);
@Autowired
private JobService jobService;
/** /**
* 计划任务执行入口 * 计划任务执行入口
*/ */
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
System.out.println(context.getMergedJobDataMap().get(ScheduleConfig.JOB_PARAM_KEY));
JobCommon jobCommon = (JobCommon)context.getMergedJobDataMap().get(ScheduleConfig.JOB_PARAM_KEY); JobCommon jobCommon = (JobCommon)context.getMergedJobDataMap().get(ScheduleConfig.JOB_PARAM_KEY);
String sJobID = jobCommon.getsJobID(); String sJobID = jobCommon.getsJobID();
Object data = jobCommon.getData(); Object data = jobCommon.getData();
...@@ -30,6 +30,8 @@ public class ScheduleJob extends QuartzJobBean { ...@@ -30,6 +30,8 @@ public class ScheduleJob extends QuartzJobBean {
} }
//调用业务逻辑 //调用业务逻辑
JobService jobService = JobsApplication.getBean(JobService.class);
System.out.println(jobService);
jobService.executeJob(jobCommon); jobService.executeJob(jobCommon);
} }
......
...@@ -88,6 +88,7 @@ public class ScheduleUtils { ...@@ -88,6 +88,7 @@ public class ScheduleUtils {
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(jobKey).build(); JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(jobKey).build();
jobDetail.getJobDataMap().put(ScheduleConfig.JOB_PARAM_KEY, jobCommon); jobDetail.getJobDataMap().put(ScheduleConfig.JOB_PARAM_KEY, jobCommon);
scheduler.scheduleJob(jobDetail, trigger); scheduler.scheduleJob(jobDetail, trigger);
// 暂停任务
if (nRunFlg == RunFlag.PAUSE.getValue()) { if (nRunFlg == RunFlag.PAUSE.getValue()) {
pauseJob(scheduler, sJobID); pauseJob(scheduler, sJobID);
} }
......
...@@ -44,13 +44,14 @@ public class JobController { ...@@ -44,13 +44,14 @@ public class JobController {
Map<String,Object> params = jobService.queryById(id); Map<String,Object> params = jobService.queryById(id);
if(params != null) { if(params != null) {
if(type.equals("start")) { if(type.equals("start")) {
ScheduleUtils.deleteScheduleJob(scheduler, id);
JobCommon jobCommon=new JobCommon(); JobCommon jobCommon=new JobCommon();
jobCommon.setsJobID(id); jobCommon.setsJobID(id);
jobCommon.setnRunFlg(0); jobCommon.setnRunFlg(0);
jobCommon.setsCronExpression(params.get("sCron")+""); jobCommon.setsCronExpression(params.get("sCron")+"");
jobCommon.setData(params.get("sClass")); jobCommon.setData(params.get("sClass"));
ScheduleUtils.createScheduleJob(scheduler, jobCommon); ScheduleUtils.createScheduleJob(scheduler, jobCommon);
ScheduleUtils.resumeJob(scheduler, id); ScheduleUtils.run(scheduler, jobCommon);
}else if(type.equals("stop")) { }else if(type.equals("stop")) {
ScheduleUtils.deleteScheduleJob(scheduler, id); ScheduleUtils.deleteScheduleJob(scheduler, id);
}else { }else {
......
...@@ -20,3 +20,14 @@ spring.datasource.shop.testWhileIdle=true ...@@ -20,3 +20,14 @@ spring.datasource.shop.testWhileIdle=true
spring.datasource.shop.validationQueryTimeout=5 spring.datasource.shop.validationQueryTimeout=5
spring.datasource.shop.validationQuery=SELECT 1 spring.datasource.shop.validationQuery=SELECT 1
spring.datasource.shop.timeBetweenEvictionRunsMillis=3600000 spring.datasource.shop.timeBetweenEvictionRunsMillis=3600000
spring.redis.database=0
spring.redis.host=10.10.0.15
spring.redis.port=16379
spring.redis.password=
spring.redis.timeout=2000
spring.redis.pool.max-active=20
spring.redis.pool.max-wait=2000
spring.redis.pool.max-idle=5
spring.redis.pool.min-idle=0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment