feat(pipelines): list commit logs 使用直接订阅。
替代了先查询再订阅,确保数据不丢失。
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
|
||||
import { CreatePipelineInput } from './dtos/create-pipeline.input';
|
||||
import { UpdatePipelineInput } from './dtos/update-pipeline.input';
|
||||
import { Pipeline } from './pipeline.entity';
|
||||
@ -43,8 +43,15 @@ export class PipelinesResolver {
|
||||
return await this.service.remove(id);
|
||||
}
|
||||
|
||||
@Query(() => String)
|
||||
@Subscription(() => LogList, {
|
||||
resolve: (value) => {
|
||||
return value;
|
||||
},
|
||||
})
|
||||
async listLogsForPipeline(@Args('id', { type: () => String }) id: string) {
|
||||
return await this.service.listLogsForPipeline(id);
|
||||
const job = await this.service.listLogsForPipeline(id);
|
||||
return (async function* () {
|
||||
yield await job.finished();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ describe('PipelinesService', () => {
|
||||
const add = jest.spyOn(queue, 'add');
|
||||
await expect(
|
||||
service.listLogsForPipeline('test-pipeline'),
|
||||
).resolves.toEqual(1);
|
||||
).resolves.toEqual({ id: 1 });
|
||||
expect(add).toBeCalledWith({
|
||||
project: pipeline.project,
|
||||
branch: pipeline.branch,
|
||||
|
@ -50,6 +50,6 @@ export class PipelinesService extends BaseDbService<Pipeline> {
|
||||
project: pipeline.project,
|
||||
branch: pipeline.branch,
|
||||
});
|
||||
return job.id;
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user