新增自动任务调度器
This commit is contained in:
parent
0a0a752b44
commit
35d5a4b8a2
|
|
@ -9,12 +9,12 @@ import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
//@EnableDiscoveryClient
|
//@EnableDiscoveryClient
|
||||||
//@MapperScan("com.qihang.oms.mapper")
|
//@MapperScan("com.qihang.oms.mapper")
|
||||||
@ComponentScan(basePackages={"cn.qihangerp.open","cn.qihangerp"})
|
@ComponentScan(basePackages={"cn.qihangerp.oms","cn.qihangerp"})
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class OmsApi {
|
public class OmsApi {
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
System.out.println( "Hello open-api!" );
|
System.out.println( "Hello oms-api!" );
|
||||||
SpringApplication.run(OmsApi.class, args);
|
SpringApplication.run(OmsApi.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package cn.qihangerp.oms.task;
|
||||||
|
|
||||||
|
import cn.qihangerp.common.task.SchedulingConfiguration;
|
||||||
|
import lombok.extern.java.Log;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
@Log
|
||||||
|
@Component
|
||||||
|
public class CronTaskLoader implements ApplicationRunner {
|
||||||
|
// private static final Logger log = LoggerFactory.getLogger(CronTaskLoader.class);
|
||||||
|
private final SchedulingConfiguration schedulingConfiguration;
|
||||||
|
private final AtomicBoolean appStarted = new AtomicBoolean(false);
|
||||||
|
private final AtomicBoolean initializing = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
public CronTaskLoader(SchedulingConfiguration schedulingConfiguration) {
|
||||||
|
this.schedulingConfiguration = schedulingConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务配置刷新(10分钟刷新一次)
|
||||||
|
*/
|
||||||
|
@Scheduled(fixedDelay = 600000)
|
||||||
|
public void cronTaskConfigRefresh() {
|
||||||
|
if (appStarted.get() && initializing.compareAndSet(false, true)) {
|
||||||
|
log.info("定时调度任务动态加载开始>>>>>>");
|
||||||
|
try {
|
||||||
|
schedulingConfiguration.refresh();
|
||||||
|
} finally {
|
||||||
|
initializing.set(false);
|
||||||
|
}
|
||||||
|
// log.info("定时调度任务动态加载结束<<<<<<");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) {
|
||||||
|
if (appStarted.compareAndSet(false, true)) {
|
||||||
|
cronTaskConfigRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import cn.qihangerp.module.service.SysTaskLogsService;
|
||||||
import cn.qihangerp.security.common.BaseController;
|
import cn.qihangerp.security.common.BaseController;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,6 +47,11 @@ public class SysTaskController extends BaseController
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody SysTask task)
|
public AjaxResult edit(@RequestBody SysTask task)
|
||||||
{
|
{
|
||||||
|
if(StringUtils.hasText(task.getCron())&&!task.getCron().equals("-")){
|
||||||
|
task.setStatus(1);
|
||||||
|
}else{
|
||||||
|
task.setStatus(0);
|
||||||
|
}
|
||||||
return toAjax(taskService.updateById(task));
|
return toAjax(taskService.updateById(task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue