Skip to content

Commit

Permalink
add future cron tab run times button
Browse files Browse the repository at this point in the history
  • Loading branch information
xxzuo committed Apr 22, 2024
1 parent 23e399f commit 13de46a
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ public Object getListByJobId(@PathVariable Long jobId) {
public Object showCron(@Valid @RequestBody MapParam mapParam) throws DataVinesServerException {
return jobScheduleService.getCron(mapParam);
}


@ApiOperation(value = "get future cron run time list")
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/cron/future/list")
public Object listFutureCronRunTimes(@Valid @RequestBody MapParam mapParam) throws DataVinesServerException {
return jobScheduleService.listFutureCronRunTimes(mapParam.getCrontab());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import io.datavines.common.utils.DateUtils;
import io.datavines.common.utils.JSONUtils;
import io.datavines.core.enums.Status;
import io.datavines.core.exception.DataVinesServerException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;

import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;

import com.google.common.collect.Maps;

import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -230,7 +233,28 @@ private static Date buildDate(LocalDateTime localDateTime){
return Date.from(instant);
}

public boolean isValid(String cronExpression){
public boolean isValid(String cronExpression) {
return CronExpression.isValidExpression(cronExpression);
}


/**
* get future cron run time list
* @param cronExpression cron expression
* @param numTimes cron run nums
* @return future cron run time list
*/
public List<String> listFutureCronRunTimes(String cronExpression, Integer numTimes) {
CronTriggerImpl cronTrigger = new CronTriggerImpl();
if (!isValid(cronExpression)) {
throw new DataVinesServerException(Status.SCHEDULE_CRON_IS_INVALID_ERROR, cronExpression);
}
try {
cronTrigger.setCronExpression(cronExpression);
} catch (ParseException e) {
throw new DataVinesServerException(Status.SCHEDULE_CRON_IS_INVALID_ERROR, cronExpression);
}
List<Date> computedFireTimeList = TriggerUtils.computeFireTimes(cronTrigger, null, numTimes);
return CollectionUtils.isEmpty(computedFireTimeList) ? new ArrayList<>() : computedFireTimeList.stream().map(DateUtils::dateToString).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public interface JobScheduleService extends IService<JobSchedule> {
JobSchedule getByJobId(Long jobId);

List<String> getCron(MapParam mapParam);

List<String> listFutureCronRunTimes(String cronExpression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public List<String> getCron(MapParam mapParam){
return listCron;
}

@Override
public List<String> listFutureCronRunTimes(String cronExpression) {
return quartzExecutor.listFutureCronRunTimes(cronExpression, 10);
}

private void updateJobScheduleParam(JobSchedule jobSchedule, String type, MapParam param) {
String paramStr = JSONUtils.toJsonString(param);
switch (JobScheduleType.of(type)){
Expand Down
2 changes: 1 addition & 1 deletion datavines-ui/Editor/components/Database/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { setEditorFn, useEditorActions, useEditorContextState } from '@Editor/st
import { IF } from '@Editor/common';
import { useIntl } from 'react-intl';
import dayjs, { Dayjs } from 'dayjs';
import TextArea from 'antd/lib/input/TextArea';
import useRequest from '../../hooks/useRequest';
import { useWatch, usePersistFn } from '@/common';
import {
Expand All @@ -26,7 +27,6 @@ import Schedule from '@/view/Main/HomeDetail/Jobs/components/Schedule';
import SearchForm from './SearchForm';
import store from '@/store';
import { useLogger } from '@/view/Main/HomeDetail/Jobs/useLogger';
import TextArea from "antd/lib/input/TextArea";

type DIndexProps = {
onShowModal?: (...args: any[]) => any;
Expand Down
2 changes: 2 additions & 0 deletions datavines-ui/src/locale/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,6 @@ export default {
quality_dashboard_profile: 'Quality Profile',
quality_dashboard_trend: 'Quality Trend',
quality_dashboard_failure_execution: 'Fail Check',

next_ten_cron_run_times: 'Next ten cron run times',
};
2 changes: 2 additions & 0 deletions datavines-ui/src/locale/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,6 @@ export default {
quality_dashboard_profile: '质量概览',
quality_dashboard_trend: '质量趋势',
quality_dashboard_failure_execution: '失败作业',

next_ten_cron_run_times: '未来十次执行时间',
};
Loading

0 comments on commit 13de46a

Please sign in to comment.