mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: add cron validate controller
This commit is contained in:
parent
1d9ebc91ba
commit
8d369ffd21
@ -3,6 +3,7 @@ package com.github.kfcfans.powerjob.server.web;
|
|||||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
import org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException;
|
import org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@ -34,6 +35,6 @@ public class ControllerExceptionHandler {
|
|||||||
} else {
|
} else {
|
||||||
log.error("[ControllerException] http request failed.", e);
|
log.error("[ControllerException] http request failed.", e);
|
||||||
}
|
}
|
||||||
return ResultDTO.failed(e.getMessage());
|
return ResultDTO.failed(ExceptionUtils.getMessage(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.github.kfcfans.powerjob.server.web.controller;
|
||||||
|
|
||||||
|
import com.github.kfcfans.powerjob.common.OmsConstant;
|
||||||
|
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||||
|
import com.github.kfcfans.powerjob.server.common.utils.CronExpression;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工具 Controller
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2020/11/28
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/tool")
|
||||||
|
public class ToolController {
|
||||||
|
|
||||||
|
@GetMapping("/validateCron")
|
||||||
|
public ResultDTO<List<String>> calculateNextCronTriggerTime(String expression) throws Exception {
|
||||||
|
CronExpression cronExpression = new CronExpression(expression);
|
||||||
|
List<String> result = Lists.newArrayList();
|
||||||
|
Date time = new Date();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
Date nextValidTime = cronExpression.getNextValidTimeAfter(time);
|
||||||
|
if (nextValidTime == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result.add(DateFormatUtils.format(nextValidTime.getTime(), OmsConstant.TIME_PATTERN));
|
||||||
|
time = nextValidTime;
|
||||||
|
}
|
||||||
|
return ResultDTO.success(result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user