Commit d1487b51 authored by zhangyong's avatar zhangyong

1

parent d17d6fe2
......@@ -21,11 +21,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<!-- <dependency> https://blog.csdn.net/liuxiaochang_2011/article/details/80663093
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
......
package com.egolm.jobs.config.schedule;
import java.io.Serializable;
import java.util.Date;
public class JobCommon {
public class JobCommon implements Serializable {
private static final long serialVersionUID = 1L;
private String sJobID;
private Integer nRunFlg;
private String sCronExpression;
......
......@@ -4,23 +4,23 @@ import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.egolm.common.StringUtil;
import com.egolm.jobs.JobsApplication;
import com.egolm.jobs.service.JobService;
public class ScheduleJob extends QuartzJobBean {
private static final Logger logger = LoggerFactory.getLogger(ScheduleJob.class);
@Autowired
private JobService jobService;
/**
* 计划任务执行入口
*/
@Override
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);
String sJobID = jobCommon.getsJobID();
Object data = jobCommon.getData();
......@@ -29,8 +29,10 @@ public class ScheduleJob extends QuartzJobBean {
throw new XScheduleException("任务定义实体[data]不能为空");
}
//调用业务逻辑
//调用业务逻辑
JobService jobService = JobsApplication.getBean(JobService.class);
System.out.println(jobService);
jobService.executeJob(jobCommon);
}
}
}
......@@ -88,12 +88,13 @@ public class ScheduleUtils {
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(jobKey).build();
jobDetail.getJobDataMap().put(ScheduleConfig.JOB_PARAM_KEY, jobCommon);
scheduler.scheduleJob(jobDetail, trigger);
// 暂停任务
if (nRunFlg == RunFlag.PAUSE.getValue()) {
pauseJob(scheduler, sJobID);
}
} catch (SchedulerException e) {
throw new XScheduleException("创建定时任务失败", e);
}
}
}
/**
......
......@@ -44,13 +44,14 @@ public class JobController {
Map<String,Object> params = jobService.queryById(id);
if(params != null) {
if(type.equals("start")) {
ScheduleUtils.deleteScheduleJob(scheduler, id);
JobCommon jobCommon=new JobCommon();
jobCommon.setsJobID(id);
jobCommon.setnRunFlg(0);
jobCommon.setsCronExpression(params.get("sCron")+"");
jobCommon.setData(params.get("sClass"));
ScheduleUtils.createScheduleJob(scheduler, jobCommon);
ScheduleUtils.resumeJob(scheduler, id);
ScheduleUtils.run(scheduler, jobCommon);
}else if(type.equals("stop")) {
ScheduleUtils.deleteScheduleJob(scheduler, id);
}else {
......
......@@ -19,4 +19,15 @@ spring.datasource.shop.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerD
spring.datasource.shop.testWhileIdle=true
spring.datasource.shop.validationQueryTimeout=5
spring.datasource.shop.validationQuery=SELECT 1
spring.datasource.shop.timeBetweenEvictionRunsMillis=3600000
\ No newline at end of file
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