feat(pipelines): list commit logs 使用直接订阅。
替代了先查询再订阅,确保数据不丢失。
This commit is contained in:
@ -1,24 +1,14 @@
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
import { ReposService } from './repos.service';
|
||||
import { Processor, Process } from '@nestjs/bull';
|
||||
import { Job } from 'bull';
|
||||
import { ListLogsOption } from './models/list-logs.options';
|
||||
import {
|
||||
LIST_LOGS_DONE,
|
||||
LIST_LOGS_PUB_SUB,
|
||||
LIST_LOGS_TASK,
|
||||
} from './repos.constants';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { LIST_LOGS_TASK } from './repos.constants';
|
||||
@Processor(LIST_LOGS_TASK)
|
||||
export class ListLogsConsumer {
|
||||
constructor(
|
||||
private readonly service: ReposService,
|
||||
@Inject(LIST_LOGS_PUB_SUB)
|
||||
private readonly pubSub: PubSub,
|
||||
) {}
|
||||
constructor(private readonly service: ReposService) {}
|
||||
@Process()
|
||||
async listLogs(job: Job<ListLogsOption>) {
|
||||
const logs = await this.service.listLogs(job.data);
|
||||
this.pubSub.publish(LIST_LOGS_DONE, logs);
|
||||
return logs;
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,7 @@ import { ListLogsConsumer } from './list-logs.consumer';
|
||||
name: LIST_LOGS_TASK,
|
||||
}),
|
||||
],
|
||||
providers: [
|
||||
ReposResolver,
|
||||
ReposService,
|
||||
ListLogsConsumer,
|
||||
{
|
||||
provide: LIST_LOGS_PUB_SUB,
|
||||
useValue: new PubSub(),
|
||||
},
|
||||
],
|
||||
providers: [ReposResolver, ReposService, ListLogsConsumer],
|
||||
exports: [ReposService],
|
||||
})
|
||||
export class ReposModule {}
|
||||
|
@ -1,21 +1,4 @@
|
||||
import { LIST_LOGS_DONE, LIST_LOGS_PUB_SUB } from './repos.constants';
|
||||
import { Resolver, Subscription } from '@nestjs/graphql';
|
||||
import { LogList } from './dtos/log-list.model';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { PubSub } from 'apollo-server-express';
|
||||
import { Resolver } from '@nestjs/graphql';
|
||||
|
||||
@Resolver()
|
||||
export class ReposResolver {
|
||||
constructor(
|
||||
@Inject(LIST_LOGS_PUB_SUB)
|
||||
private readonly pubSub: PubSub,
|
||||
) {}
|
||||
@Subscription(() => LogList, {
|
||||
resolve: (value) => {
|
||||
return value;
|
||||
},
|
||||
})
|
||||
listLogsDone() {
|
||||
return this.pubSub.asyncIterator(LIST_LOGS_DONE);
|
||||
}
|
||||
}
|
||||
export class ReposResolver {}
|
||||
|
Reference in New Issue
Block a user