feat(pipeline-task): 流水线任务日志订阅接口。

This commit is contained in:
Ivan Li
2021-03-15 13:30:52 +08:00
parent aa92c518f0
commit 4e7c825170
12 changed files with 15803 additions and 23 deletions

View File

@@ -18,13 +18,13 @@ import { ApplicationException } from '../commons/exceptions/application.exceptio
import { PipelineUnits } from './enums/pipeline-units.enum';
import { PipelineTaskLogMessage } from './models/pipeline-task-log-message.module';
import { TaskStatuses } from './enums/task-statuses.enum';
import { PipelineTaskLogsService } from './pipeline-task-logs.service';
@Processor(PIPELINE_TASK_QUEUE)
export class PipelineTaskConsumer {
constructor(
private readonly service: PipelineTasksService,
private readonly reposService: ReposService,
@InjectQueue(PIPELINE_TASK_LOG_QUEUE)
private readonly logQueue: Queue<PipelineTaskLogMessage>,
private readonly logsService: PipelineTaskLogsService,
) {}
@Process()
async doTask({ data: task, update }: Job<PipelineTask>) {
@@ -68,14 +68,14 @@ export class PipelineTaskConsumer {
} finally {
unitLog.endedAt = new Date();
task.logs.push(unitLog);
update(task);
// await update(task);
}
}
} catch (err) {
console.log(err);
} finally {
task = await this.service.updateTask(task);
update(task);
await update(task);
}
}
@@ -95,12 +95,12 @@ export class PipelineTaskConsumer {
const str = data.toString();
errorMessages.push(str);
logs.push(str);
this.logQueue.add(PipelineTaskLogMessage.create(task, str));
this.logsService.recordLog(PipelineTaskLogMessage.create(task, str));
});
sub.stdout.on('data', (data: Buffer) => {
const str = data.toString();
logs.push(str);
this.logQueue.add(PipelineTaskLogMessage.create(task, str));
this.logsService.recordLog(PipelineTaskLogMessage.create(task, str));
});
sub.addListener('close', (code) => {
if (code === 0) {