Former-commit-id: c049a3cd4a0fb4ae72302b64aca698ac989111b8master
commit
018e27b6e1
@ -0,0 +1,14 @@
|
||||
package ${basePackage}.frame.schedule;
|
||||
|
||||
import org.springframework.scheduling.config.CronTask;
|
||||
import org.springframework.scheduling.config.Task;
|
||||
|
||||
public abstract class RunCronTask extends RunTask {
|
||||
|
||||
abstract String cron();
|
||||
|
||||
@Override
|
||||
public Task build() {
|
||||
return new CronTask(this, cron());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ${basePackage}.frame.schedule;
|
||||
|
||||
import org.springframework.scheduling.config.FixedDelayTask;
|
||||
import org.springframework.scheduling.config.FixedRateTask;
|
||||
import org.springframework.scheduling.config.Task;
|
||||
|
||||
public abstract class RunRepeatTask extends RunTask {
|
||||
|
||||
public abstract void config(Config config);
|
||||
|
||||
public class Config {
|
||||
int interval = 10 * 60 * 1000;
|
||||
int initialDelay = 0;
|
||||
boolean fix = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task build() {
|
||||
Config config = new Config();
|
||||
config(config);
|
||||
|
||||
if (config.fix) {
|
||||
return new FixedRateTask(this, config.interval, config.initialDelay);
|
||||
} else {
|
||||
return new FixedDelayTask(this, config.interval, config.initialDelay);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package ${basePackage}.frame.schedule;
|
||||
|
||||
public abstract class RunSqlTask extends RunRepeatTask {
|
||||
|
||||
public abstract String getSql();
|
||||
|
||||
@Override
|
||||
public void config(Config config) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//exec sql
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ${basePackage}.frame.schedule;
|
||||
|
||||
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.config.Task;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
public abstract class RunTask implements Runnable {
|
||||
|
||||
public abstract String taskId();
|
||||
|
||||
public abstract Task build();
|
||||
|
||||
public void configChange(ThreadPoolTaskScheduler scheduler) {
|
||||
ScheduledFuture<?> schedule = scheduler.schedule(this, new Date());
|
||||
if (!schedule.cancel(true)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue