mirror of https://github.com/certd/certd
perf: 支持批量重新运行
parent
36b02c2cec
commit
818998259d
|
@ -489,7 +489,15 @@ export class Executor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stepId 如果==ALL 清除所有
|
||||
*/
|
||||
clearLastStatus(stepId: string) {
|
||||
if (stepId === "ALL") {
|
||||
this.lastStatusMap.clear();
|
||||
return;
|
||||
}
|
||||
this.lastStatusMap.clearById(stepId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ export async function Cancel(historyId: any) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function BatchUpdateGroup(pipelineIds: number[], groupId: number): Promise<CertInfo> {
|
||||
export async function BatchUpdateGroup(pipelineIds: number[], groupId: number): Promise<void> {
|
||||
return await request({
|
||||
url: apiPrefix + "/batchUpdateGroup",
|
||||
method: "post",
|
||||
|
@ -84,13 +84,20 @@ export async function BatchUpdateGroup(pipelineIds: number[], groupId: number):
|
|||
});
|
||||
}
|
||||
|
||||
export async function BatchDelete(pipelineIds: number[]): Promise<CertInfo> {
|
||||
export async function BatchDelete(pipelineIds: number[]): Promise<void> {
|
||||
return await request({
|
||||
url: apiPrefix + "/batchDelete",
|
||||
method: "post",
|
||||
data: { ids: pipelineIds },
|
||||
});
|
||||
}
|
||||
export async function BatchRerun(pipelineIds: number[]): Promise<void> {
|
||||
return await request({
|
||||
url: apiPrefix + "/batchRerun",
|
||||
method: "post",
|
||||
data: { ids: pipelineIds },
|
||||
});
|
||||
}
|
||||
|
||||
export async function GetFiles(pipelineId: number) {
|
||||
return await request({
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<span> 已选择 {{ selectedRowKeys.length }} 项 </span>
|
||||
<fs-button icon="ion:trash-outline" class="color-green" type="link" text="批量删除" @click="batchDelete"></fs-button>
|
||||
<change-group class="color-green" :selected-row-keys="selectedRowKeys" @change="groupChanged"></change-group>
|
||||
<fs-button icon="icon-park-outline:replay-music" class="need-plus" type="link" text="强制重新运行" @click="batchRerun"></fs-button>
|
||||
</div>
|
||||
</div>
|
||||
<template #actionbar-right> </template>
|
||||
|
@ -70,6 +71,19 @@ function batchDelete() {
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
function batchRerun() {
|
||||
Modal.confirm({
|
||||
title: "确认强制重新运行吗",
|
||||
content: "确定要强制重新运行选中流水线吗?(20条一批执行)",
|
||||
async onOk() {
|
||||
await api.BatchRerun(selectedRowKeys.value);
|
||||
notification.success({ message: "任务已提交" });
|
||||
await crudExpose.doRefresh();
|
||||
selectedRowKeys.value = [];
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<style lang="less">
|
||||
.batch-actions {
|
||||
|
|
|
@ -122,4 +122,10 @@ export class PipelineController extends CrudController<PipelineService> {
|
|||
await this.service.batchUpdateGroup(ids, groupId, this.getUserId());
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchRerun', { summary: Constants.per.authOnly })
|
||||
async batchRerun(@Body('ids') ids: number[]) {
|
||||
await this.service.batchRerun(ids, this.getUserId());
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import {CnameRecordService} from "../../cname/service/cname-record-service.js";
|
|||
import {PluginConfigGetter} from "../../plugin/service/plugin-config-getter.js";
|
||||
import dayjs from "dayjs";
|
||||
import {DbAdapter} from "../../db/index.js";
|
||||
import {isComm} from "@certd/plus-core";
|
||||
import {isComm, isPlus} from "@certd/plus-core";
|
||||
import {logger} from "@certd/basic";
|
||||
import {UrlService} from "./url-service.js";
|
||||
import {NotificationService} from "./notification-service.js";
|
||||
|
@ -429,6 +429,12 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||
logger.info('当前定时器数量:', this.cron.getTaskSize());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @param triggerId =null手动启动
|
||||
* @param stepId 如果传入ALL,清空所有状态
|
||||
*/
|
||||
async run(id: number, triggerId: string, stepId?: string) {
|
||||
const entity: PipelineEntity = await this.info(id);
|
||||
await this.doRun(entity, triggerId, stepId);
|
||||
|
@ -684,6 +690,42 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
|||
{ groupId }
|
||||
);
|
||||
}
|
||||
async batchRerun(ids: number[], userId: any) {
|
||||
if (!isPlus()){
|
||||
throw new NeedVIPException("此功能需要升级专业版")
|
||||
}
|
||||
|
||||
if (!userId || ids.length === 0) {
|
||||
return;
|
||||
}
|
||||
const list = await this.repository.find({
|
||||
select:{
|
||||
id:true
|
||||
},
|
||||
where:{
|
||||
id: In(ids),
|
||||
userId
|
||||
}
|
||||
})
|
||||
|
||||
ids = list.map(item=>item.id)
|
||||
|
||||
//异步执行
|
||||
this.startBatchRerun(ids)
|
||||
}
|
||||
|
||||
async startBatchRerun(ids: number[]){
|
||||
//20条一批
|
||||
const batchSize = 20;
|
||||
for (let i = 0; i < ids.length; i += batchSize) {
|
||||
const batchIds = ids.slice(i, i + batchSize);
|
||||
const batchPromises = batchIds.map(async (id)=>{
|
||||
await this.run(id,null,"ALL")
|
||||
});
|
||||
await Promise.all(batchPromises)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getUserPipelineCount(userId) {
|
||||
return await this.repository.count({ where: { userId } });
|
||||
|
|
Loading…
Reference in New Issue