mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: optimize out of data's cron expression and passed the test
This commit is contained in:
parent
8560112432
commit
763e416be3
@ -194,7 +194,7 @@ public class JobService {
|
||||
CronExpression cronExpression = new CronExpression(jobInfoDO.getTimeExpression());
|
||||
Date nextValidTime = cronExpression.getNextValidTimeAfter(now);
|
||||
if (nextValidTime == null) {
|
||||
throw new PowerJobException("invalid cron expression: " + jobInfoDO.getTimeExpression());
|
||||
throw new PowerJobException("cron expression is out of date: " + jobInfoDO.getTimeExpression());
|
||||
}
|
||||
jobInfoDO.setNextTriggerTime(nextValidTime.getTime());
|
||||
}else if (timeExpressionType == TimeExpressionType.API || timeExpressionType == TimeExpressionType.WORKFLOW) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.kfcfans.powerjob.server.web.controller;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.InstanceStatus;
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import com.github.kfcfans.powerjob.server.akka.OhMyServer;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.OmsFileUtils;
|
||||
@ -145,10 +146,10 @@ public class InstanceController {
|
||||
private String getTargetServer(Long instanceId) {
|
||||
InstanceInfoDO instanceInfo = instanceInfoRepository.findByInstanceId(instanceId);
|
||||
if (instanceInfo == null) {
|
||||
throw new RuntimeException("invalid instanceId: " + instanceId);
|
||||
throw new PowerJobException("invalid instanceId: " + instanceId);
|
||||
}
|
||||
|
||||
Optional<AppInfoDO> appInfoOpt = appInfoRepository.findById(instanceInfo.getAppId());
|
||||
return appInfoOpt.orElseThrow(() -> new RuntimeException("impossible")).getCurrentServer();
|
||||
return appInfoOpt.orElseThrow(() -> new PowerJobException("impossible")).getCurrentServer();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.github.kfcfans.powerjob.server.test;
|
||||
|
||||
|
||||
import com.github.kfcfans.powerjob.server.common.utils.CronExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* CRON 测试
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2020/10/8
|
||||
*/
|
||||
public class CronTest {
|
||||
|
||||
private static final String FIXED_CRON = "0 0 13 8 10 ? 2020-2020";
|
||||
|
||||
@Test
|
||||
public void testFixedTimeCron() throws Exception {
|
||||
CronExpression cronExpression = new CronExpression(FIXED_CRON);
|
||||
System.out.println(cronExpression.getCronExpression());
|
||||
System.out.println(cronExpression.getNextValidTimeAfter(new Date()));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user