mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: cancel task
This commit is contained in:
@@ -11,6 +11,7 @@ import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { HistoryService } from '../service/history-service';
|
||||
|
||||
/**
|
||||
* 证书
|
||||
@@ -20,6 +21,8 @@ import { Constants } from '../../../basic/constants';
|
||||
export class PipelineController extends CrudController<PipelineService> {
|
||||
@Inject()
|
||||
service: PipelineService;
|
||||
@Inject()
|
||||
historyService: HistoryService;
|
||||
|
||||
getService() {
|
||||
return this.service;
|
||||
@@ -77,4 +80,11 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
await this.service.trigger(id);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/cancel', { summary: Constants.per.authOnly })
|
||||
async cancel(@Query('historyId') historyId) {
|
||||
await this.historyService.checkUserId(historyId, this.ctx.user.id);
|
||||
await this.service.cancel(historyId);
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail';
|
||||
import { Executor, Pipeline, RunHistory } from '@certd/pipeline';
|
||||
import { Executor, Pipeline, ResultType, RunHistory } from '@certd/pipeline';
|
||||
import { AccessService } from './access-service';
|
||||
import { DbStorage } from './db-storage';
|
||||
import { StorageService } from './storage-service';
|
||||
@@ -235,7 +235,13 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
async cancel(historyId: number) {
|
||||
const executor = runningTasks.get(historyId);
|
||||
if (executor) {
|
||||
executor.cancel();
|
||||
await executor.cancel();
|
||||
} else {
|
||||
const entity = await this.historyService.info(historyId);
|
||||
const pipeline: Pipeline = JSON.parse(entity.pipeline);
|
||||
pipeline.status.status = ResultType.canceled;
|
||||
const runtime = new RunHistory(historyId, null, pipeline);
|
||||
await this.saveHistory(runtime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user