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; commit: string;
@Field(() => PipelineUnits)
units: PipelineUnits[]; units: PipelineUnits[];
} }

View File

@ -1,6 +1,13 @@
import { registerEnumType } from '@nestjs/graphql';
export enum TaskStatuses { export enum TaskStatuses {
success = 'success', success = 'success',
failed = 'failed', failed = 'failed',
working = 'working', working = 'working',
pending = 'pending', pending = 'pending',
} }
registerEnumType(TaskStatuses, {
name: 'TaskStatuses',
description: '任务状态',
});

View File

@ -1,7 +1,12 @@
import { TaskStatuses } from '../enums/task-statuses.enum'; import { TaskStatuses } from '../enums/task-statuses.enum';
import { PipelineUnits } from '../enums/pipeline-units.enum'; import { PipelineUnits } from '../enums/pipeline-units.enum';
import { Field, ObjectType } from '@nestjs/graphql';
@ObjectType()
export class PipelineTaskLogs { export class PipelineTaskLogs {
@Field(() => PipelineUnits)
unit: PipelineUnits; unit: PipelineUnits;
@Field(() => PipelineUnits)
status: TaskStatuses; status: TaskStatuses;
startedAt?: Date; startedAt?: Date;
endedAt?: Date; endedAt?: Date;

View File

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

View File

@ -1,5 +1,5 @@
import { AppBaseEntity } from './../commons/entities/app-base-entity'; 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 { Column, Entity, ManyToOne } from 'typeorm';
import { Pipeline } from '../pipelines/pipeline.entity'; import { Pipeline } from '../pipelines/pipeline.entity';
import { PipelineTaskLogs } from './models/pipeline-task-logs.model'; 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 }) @Column({ type: 'enum', enum: TaskStatuses, default: TaskStatuses.pending })
status: TaskStatuses; status: TaskStatuses;
@Column() @Column({ nullable: true })
startedAt: Date; startedAt?: Date;
@Column() @Column({ nullable: true })
endedAt: Date; endedAt?: Date;
} }

View File

@ -7,6 +7,7 @@ import { Pipeline } from '../pipelines/pipeline.entity';
import { ReposModule } from '../repos/repos.module'; import { ReposModule } from '../repos/repos.module';
import { RedisModule } from 'nestjs-redis'; import { RedisModule } from 'nestjs-redis';
import { BullModule } from '@nestjs/bull'; import { BullModule } from '@nestjs/bull';
import { PipelineTaskConsumer } from './pipeline-task.consumer';
import { import {
PIPELINE_TASK_QUEUE, PIPELINE_TASK_QUEUE,
PIPELINE_TASK_LOG_QUEUE, PIPELINE_TASK_LOG_QUEUE,
@ -24,6 +25,10 @@ import {
RedisModule, RedisModule,
ReposModule, ReposModule,
], ],
providers: [PipelineTasksService, PipelineTasksResolver], providers: [
PipelineTasksService,
PipelineTasksResolver,
PipelineTaskConsumer,
],
}) })
export class PipelineTasksModule {} 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() @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(); const redis = this.redis.getClient();
await redis.lpush(tasksKey, JSON.stringify(task)); await redis.lpush(tasksKey, JSON.stringify(task));
await this.doNextTask(pipeline); await this.doNextTask(pipeline);
return task;
} }
async doNextTask(pipeline: Pipeline) { async doNextTask(pipeline: Pipeline) {