refactor(pipeline, repo): rabbitmq
This commit is contained in:
@ -6,10 +6,14 @@ import { BaseDbService } from '../commons/services/base-db.service';
|
||||
import { CreatePipelineInput } from './dtos/create-pipeline.input';
|
||||
import { UpdatePipelineInput } from './dtos/update-pipeline.input';
|
||||
import { ListPipelineArgs } from './dtos/list-pipelines.args';
|
||||
import { InjectQueue } from '@nestjs/bull';
|
||||
import { LIST_LOGS_TASK } from '../repos/repos.constants';
|
||||
import { Queue } from 'bull';
|
||||
import { ListLogsOption } from '../repos/models/list-logs.options';
|
||||
import {
|
||||
EXCHANGE_REPO,
|
||||
ROUTE_FETCH,
|
||||
ROUTE_LIST_COMMITS,
|
||||
} from '../repos/repos.constants';
|
||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
||||
import { Commit } from '../repos/dtos/log-list.model';
|
||||
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
|
||||
|
||||
@Injectable()
|
||||
export class PipelinesService extends BaseDbService<Pipeline> {
|
||||
@ -17,8 +21,7 @@ export class PipelinesService extends BaseDbService<Pipeline> {
|
||||
constructor(
|
||||
@InjectRepository(Pipeline)
|
||||
readonly repository: Repository<Pipeline>,
|
||||
@InjectQueue(LIST_LOGS_TASK)
|
||||
private readonly listLogsQueue: Queue<ListLogsOption>,
|
||||
private readonly amqpConnection: AmqpConnection,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
@ -47,16 +50,27 @@ export class PipelinesService extends BaseDbService<Pipeline> {
|
||||
async remove(id: string) {
|
||||
return (await this.repository.softDelete({ id })).affected;
|
||||
}
|
||||
|
||||
async listLogsForPipeline(id: string) {
|
||||
const pipeline = await this.repository.findOneOrFail({
|
||||
where: { id },
|
||||
relations: ['project'],
|
||||
async syncCommits(pipeline: Pipeline, appInstance?: string) {
|
||||
return await this.amqpConnection.request<string | null>({
|
||||
exchange: EXCHANGE_REPO,
|
||||
routingKey: getAppInstanceRouteKey(ROUTE_FETCH, appInstance),
|
||||
payload: pipeline,
|
||||
timeout: 30_000,
|
||||
});
|
||||
const job = await this.listLogsQueue.add({
|
||||
project: pipeline.project,
|
||||
branch: pipeline.branch,
|
||||
});
|
||||
return job;
|
||||
}
|
||||
async listCommits(pipeline: Pipeline) {
|
||||
return await this.amqpConnection
|
||||
.request<Commit[]>({
|
||||
exchange: EXCHANGE_REPO,
|
||||
routingKey: ROUTE_LIST_COMMITS,
|
||||
payload: pipeline,
|
||||
timeout: 10_000,
|
||||
})
|
||||
.then((list) =>
|
||||
list.map((item) => {
|
||||
item.date = new Date(item.date);
|
||||
return item;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user