feat-pipelines #1
@ -7,6 +7,5 @@ export class CreatePipelineTaskInput {
|
||||
|
||||
commit: string;
|
||||
|
||||
@Field(() => PipelineUnits)
|
||||
units: PipelineUnits[];
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
import { registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
export enum TaskStatuses {
|
||||
success = 'success',
|
||||
failed = 'failed',
|
||||
working = 'working',
|
||||
pending = 'pending',
|
||||
}
|
||||
|
||||
registerEnumType(TaskStatuses, {
|
||||
name: 'TaskStatuses',
|
||||
description: '任务状态',
|
||||
});
|
||||
|
@ -1,7 +1,12 @@
|
||||
import { TaskStatuses } from '../enums/task-statuses.enum';
|
||||
import { PipelineUnits } from '../enums/pipeline-units.enum';
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class PipelineTaskLogs {
|
||||
@Field(() => PipelineUnits)
|
||||
unit: PipelineUnits;
|
||||
@Field(() => PipelineUnits)
|
||||
status: TaskStatuses;
|
||||
startedAt?: Date;
|
||||
endedAt?: Date;
|
||||
|
@ -68,6 +68,7 @@ export class PipelineTaskConsumer {
|
||||
} finally {
|
||||
unitLog.endedAt = new Date();
|
||||
task.logs.push(unitLog);
|
||||
update(task);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { AppBaseEntity } from './../commons/entities/app-base-entity';
|
||||
import { ObjectType } from '@nestjs/graphql';
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { Pipeline } from '../pipelines/pipeline.entity';
|
||||
import { PipelineTaskLogs } from './models/pipeline-task-logs.model';
|
||||
@ -26,9 +26,9 @@ export class PipelineTask extends AppBaseEntity {
|
||||
@Column({ type: 'enum', enum: TaskStatuses, default: TaskStatuses.pending })
|
||||
status: TaskStatuses;
|
||||
|
||||
@Column()
|
||||
startedAt: Date;
|
||||
@Column({ nullable: true })
|
||||
startedAt?: Date;
|
||||
|
||||
@Column()
|
||||
endedAt: Date;
|
||||
@Column({ nullable: true })
|
||||
endedAt?: Date;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import { Pipeline } from '../pipelines/pipeline.entity';
|
||||
import { ReposModule } from '../repos/repos.module';
|
||||
import { RedisModule } from 'nestjs-redis';
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { PipelineTaskConsumer } from './pipeline-task.consumer';
|
||||
import {
|
||||
PIPELINE_TASK_QUEUE,
|
||||
PIPELINE_TASK_LOG_QUEUE,
|
||||
@ -24,6 +25,10 @@ import {
|
||||
RedisModule,
|
||||
ReposModule,
|
||||
],
|
||||
providers: [PipelineTasksService, PipelineTasksResolver],
|
||||
providers: [
|
||||
PipelineTasksService,
|
||||
PipelineTasksResolver,
|
||||
PipelineTaskConsumer,
|
||||
],
|
||||
})
|
||||
export class PipelineTasksModule {}
|
||||
|
@ -1,4 +1,18 @@
|
||||
import { Resolver } from '@nestjs/graphql';
|
||||
import { Resolver, Args, Mutation, Subscription } from '@nestjs/graphql';
|
||||
import { PipelineTask } from './pipeline-task.entity';
|
||||
import { PipelineTasksService } from './pipeline-tasks.service';
|
||||
import { CreatePipelineTaskInput } from './dtos/create-pipeline-task.input';
|
||||
import { PipelineTaskLogMessage } from './models/pipeline-task-log-message.module';
|
||||
import { PipelineTaskLogArgs } from './dtos/pipeline-task-log.args';
|
||||
|
||||
@Resolver()
|
||||
export class PipelineTasksResolver {}
|
||||
export class PipelineTasksResolver {
|
||||
constructor(private readonly service: PipelineTasksService) {}
|
||||
|
||||
@Mutation(() => PipelineTask)
|
||||
async createPipelineTask(@Args('task') taskDto: CreatePipelineTaskInput) {
|
||||
return await this.service.addTask(taskDto);
|
||||
}
|
||||
|
||||
@Subscription(() => PipelineTaskLogMessage)
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ export class PipelineTasksService {
|
||||
const redis = this.redis.getClient();
|
||||
await redis.lpush(tasksKey, JSON.stringify(task));
|
||||
await this.doNextTask(pipeline);
|
||||
return task;
|
||||
}
|
||||
|
||||
async doNextTask(pipeline: Pipeline) {
|
||||
|
Loading…
Reference in New Issue
Block a user