mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +08:00
perf: 列表中支持下次执行时间显示
This commit is contained in:
@@ -9,7 +9,7 @@ export function getCronNextTimes(cron: string, count: number = 1) {
|
|||||||
const interval = parser.parseExpression(cron);
|
const interval = parser.parseExpression(cron);
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const next = interval.next().getTime();
|
const next = interval.next().getTime();
|
||||||
nextTimes.push(dayjs(next).format("YYYY-MM-DD HH:mm:ss"));
|
nextTimes.push(dayjs(next).valueOf());
|
||||||
}
|
}
|
||||||
return nextTimes;
|
return nextTimes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ export default {
|
|||||||
updateTime: "Update Time",
|
updateTime: "Update Time",
|
||||||
triggerType: "Trigger Type",
|
triggerType: "Trigger Type",
|
||||||
pipelineId: "Pipeline Id",
|
pipelineId: "Pipeline Id",
|
||||||
|
nextRunTime: "Next Run Time",
|
||||||
},
|
},
|
||||||
|
|
||||||
pi: {
|
pi: {
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ export default {
|
|||||||
updateTime: "更新时间",
|
updateTime: "更新时间",
|
||||||
triggerType: "触发类型",
|
triggerType: "触发类型",
|
||||||
pipelineId: "流水线Id",
|
pipelineId: "流水线Id",
|
||||||
|
nextRunTime: "下次运行时间",
|
||||||
},
|
},
|
||||||
pi: {
|
pi: {
|
||||||
validTime: "流水线有效期",
|
validTime: "流水线有效期",
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ export default function ({ crudExpose, context: { selectedRowKeys, openCertApply
|
|||||||
column: {
|
column: {
|
||||||
align: "center",
|
align: "center",
|
||||||
width: 120,
|
width: 120,
|
||||||
|
show: false,
|
||||||
sorter: true,
|
sorter: true,
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
@@ -464,6 +465,18 @@ export default function ({ crudExpose, context: { selectedRowKeys, openCertApply
|
|||||||
align: "center",
|
align: "center",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
nextRunTime: {
|
||||||
|
title: t("certd.fields.nextRunTime"),
|
||||||
|
type: "datetime",
|
||||||
|
form: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
sorter: true,
|
||||||
|
width: 150,
|
||||||
|
align: "center",
|
||||||
|
},
|
||||||
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
title: t("certd.fields.enabled"),
|
title: t("certd.fields.enabled"),
|
||||||
type: "dict-switch",
|
type: "dict-switch",
|
||||||
|
|||||||
@@ -885,6 +885,7 @@ export default defineComponent({
|
|||||||
saveLoading.value = false;
|
saveLoading.value = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const edit = () => {
|
const edit = () => {
|
||||||
pipeline.value = cloneDeep(currentPipeline.value);
|
pipeline.value = cloneDeep(currentPipeline.value);
|
||||||
currentHistory.value = null;
|
currentHistory.value = null;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ export class PipelineEntity {
|
|||||||
// 变量
|
// 变量
|
||||||
lastVars: any;
|
lastVars: any;
|
||||||
|
|
||||||
|
nextRunTime: number;
|
||||||
|
|
||||||
@Column({name: 'order', comment: '排序', nullable: true,})
|
@Column({name: 'order', comment: '排序', nullable: true,})
|
||||||
order: number;
|
order: number;
|
||||||
|
|
||||||
@@ -69,4 +71,5 @@ export class PipelineEntity {
|
|||||||
default: () => 'CURRENT_TIMESTAMP',
|
default: () => 'CURRENT_TIMESTAMP',
|
||||||
})
|
})
|
||||||
updateTime: Date;
|
updateTime: Date;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import { TaskServiceBuilder } from "./getter/task-service-getter.js";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { set } from "lodash-es";
|
import { set } from "lodash-es";
|
||||||
import { executorQueue } from "@certd/lib-server";
|
import { executorQueue } from "@certd/lib-server";
|
||||||
|
import parser from "cron-parser";
|
||||||
const runningTasks: Map<string | number, Executor> = new Map();
|
const runningTasks: Map<string | number, Executor> = new Map();
|
||||||
|
|
||||||
|
|
||||||
@@ -141,16 +141,47 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
item.stepCount = stepCount;
|
item.stepCount = stepCount;
|
||||||
if(item.triggerCount == 0 ){
|
if (item.triggerCount == 0) {
|
||||||
item.triggerCount = pipeline.triggers?.length;
|
item.triggerCount = pipeline.triggers?.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取下次执行时间
|
||||||
|
if (pipeline.triggers?.length > 0) {
|
||||||
|
const triggers = pipeline.triggers.filter((item) => item.type === 'timer');
|
||||||
|
if (triggers && triggers.length > 0) {
|
||||||
|
let nextTimes: any = [];
|
||||||
|
for (const item of triggers) {
|
||||||
|
if (!item.props?.cron) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const ret = this.getCronNextTimes(item.props?.cron, 1);
|
||||||
|
nextTimes.push(...ret);
|
||||||
|
}
|
||||||
|
item.nextRunTime = nextTimes[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
delete item.content;
|
delete item.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCronNextTimes(cron: string, count: number = 1) {
|
||||||
|
if (cron == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const nextTimes = [];
|
||||||
|
const interval = parser.parseExpression(cron);
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const next = interval.next().getTime();
|
||||||
|
nextTimes.push(dayjs(next).format("YYYY-MM-DD HH:mm:ss"));
|
||||||
|
}
|
||||||
|
return nextTimes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private async fillLastVars(records: PipelineEntity[]) {
|
private async fillLastVars(records: PipelineEntity[]) {
|
||||||
const pipelineIds: number[] = [];
|
const pipelineIds: number[] = [];
|
||||||
const recordMap = {};
|
const recordMap = {};
|
||||||
@@ -220,7 +251,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||||||
//修改
|
//修改
|
||||||
old = await this.info(bean.id);
|
old = await this.info(bean.id);
|
||||||
}
|
}
|
||||||
if (!old || !old.webhookKey ) {
|
if (!old || !old.webhookKey) {
|
||||||
bean.webhookKey = await this.genWebhookKey();
|
bean.webhookKey = await this.genWebhookKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user