feat-pipelines #1

Merged
Ivan merged 25 commits from feat-pipelines into master 2021-03-24 20:50:41 +08:00
8 changed files with 41 additions and 9 deletions
Showing only changes of commit aa92c518f0 - Show all commits

View File

@ -7,6 +7,5 @@ export class CreatePipelineTaskInput {
commit: string;
@Field(() => PipelineUnits)
units: PipelineUnits[];
}

View File

@ -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: '任务状态',
});

View File

@ -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;

View File

@ -68,6 +68,7 @@ export class PipelineTaskConsumer {
} finally {
unitLog.endedAt = new Date();
task.logs.push(unitLog);
update(task);
}
}
} catch (err) {

View File

@ -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;
}

View File

@ -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 {}

View File

@ -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)
}

View File

@ -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) {