2021-03-20 14:30:26 +08:00
|
|
|
import { Resolver, Args, Mutation, Subscription, Query } from '@nestjs/graphql';
|
2021-03-12 23:00:12 +08:00
|
|
|
import { PipelineTask } from './pipeline-task.entity';
|
|
|
|
import { PipelineTasksService } from './pipeline-tasks.service';
|
|
|
|
import { CreatePipelineTaskInput } from './dtos/create-pipeline-task.input';
|
|
|
|
import { PipelineTaskLogArgs } from './dtos/pipeline-task-log.args';
|
2021-04-04 00:36:58 +08:00
|
|
|
import { plainToClass } from 'class-transformer';
|
2021-06-05 21:34:19 +08:00
|
|
|
import { PipelineTaskLogger } from './pipeline-task.logger';
|
|
|
|
import { observableToAsyncIterable } from '@graphql-tools/utils';
|
|
|
|
import { PipelineTaskEvent } from './models/pipeline-task-event';
|
2021-03-01 18:14:13 +08:00
|
|
|
|
|
|
|
@Resolver()
|
2021-03-12 23:00:12 +08:00
|
|
|
export class PipelineTasksResolver {
|
2021-06-05 21:34:19 +08:00
|
|
|
constructor(
|
|
|
|
private readonly service: PipelineTasksService,
|
|
|
|
private readonly taskLogger: PipelineTaskLogger,
|
|
|
|
) {}
|
2021-03-12 23:00:12 +08:00
|
|
|
|
|
|
|
@Mutation(() => PipelineTask)
|
|
|
|
async createPipelineTask(@Args('task') taskDto: CreatePipelineTaskInput) {
|
|
|
|
return await this.service.addTask(taskDto);
|
|
|
|
}
|
|
|
|
|
2021-06-05 21:34:19 +08:00
|
|
|
@Subscription(() => PipelineTaskEvent, {
|
2021-03-20 14:30:26 +08:00
|
|
|
resolve: (value) => {
|
2021-06-05 21:34:19 +08:00
|
|
|
const data = plainToClass(PipelineTaskEvent, value);
|
2021-04-04 00:36:58 +08:00
|
|
|
return data;
|
2021-03-20 14:30:26 +08:00
|
|
|
},
|
|
|
|
})
|
2021-06-05 21:34:19 +08:00
|
|
|
async pipelineTaskEvent(@Args() args: PipelineTaskLogArgs) {
|
|
|
|
const task = await this.service.findTaskById(args.taskId);
|
|
|
|
return observableToAsyncIterable<PipelineTaskEvent>(
|
|
|
|
this.taskLogger.getMessage$(task.id),
|
|
|
|
);
|
2021-03-15 13:30:52 +08:00
|
|
|
}
|
2021-03-20 14:30:26 +08:00
|
|
|
|
2021-03-24 20:35:24 +08:00
|
|
|
@Subscription(() => PipelineTask, {
|
|
|
|
resolve: (value) => {
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
})
|
|
|
|
async pipelineTaskChanged(@Args('id') id: string) {
|
2021-05-30 22:36:06 +08:00
|
|
|
// return await this.service.watchTaskUpdated(id);
|
2021-03-24 20:35:24 +08:00
|
|
|
}
|
|
|
|
|
2021-03-20 14:30:26 +08:00
|
|
|
@Query(() => [PipelineTask])
|
|
|
|
async listPipelineTaskByPipelineId(@Args('pipelineId') pipelineId: string) {
|
|
|
|
return await this.service.listTasksByPipelineId(pipelineId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Query(() => PipelineTask)
|
2021-05-23 17:51:14 +08:00
|
|
|
async pipelineTask(@Args('id') id: string) {
|
2021-03-20 14:30:26 +08:00
|
|
|
return await this.service.findTaskById(id);
|
|
|
|
}
|
2021-05-23 17:51:14 +08:00
|
|
|
|
|
|
|
@Mutation(() => Boolean)
|
|
|
|
async stopPipelineTask(@Args('id') id: string) {
|
|
|
|
const task = await this.service.findTaskById(id);
|
|
|
|
}
|
2021-03-12 23:00:12 +08:00
|
|
|
}
|