feat:时间校验
This commit is contained in:
@@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -21,8 +20,12 @@ public class DynamicTaskScheduler {
|
|||||||
|
|
||||||
|
|
||||||
public void schedule(TaskConfig config, Runnable task) {
|
public void schedule(TaskConfig config, Runnable task) {
|
||||||
|
schedule(config, task, LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void schedule(TaskConfig config, Runnable task, LocalDateTime serverTime) {
|
||||||
LocalDateTime time = config.getExecutionTime();
|
LocalDateTime time = config.getExecutionTime();
|
||||||
if (time.isBefore(LocalDateTime.now())) return;
|
if (time.isBefore(serverTime)) return;
|
||||||
|
|
||||||
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user