2026-04-07 13:20:31 +02:00
|
|
|
import { lineToCreateLineDto, ObjeniousLine } from "sim-shared/domain/objeniousLine.js";
|
2026-04-28 15:23:27 +02:00
|
|
|
import { ObjeniousLinesRepository } from "sim-shared/infrastructure/ObjeniousLinesRepository.js";
|
2026-04-08 13:48:57 +02:00
|
|
|
import { ObjeniousOperationsRepository } from "sim-shared/infrastructure/ObjeniousOperationRepository.js";
|
2026-03-24 17:27:52 +01:00
|
|
|
|
2026-03-26 09:29:09 +01:00
|
|
|
export class TaskVolcadoLineas {
|
2026-03-24 17:27:52 +01:00
|
|
|
constructor(
|
2026-03-26 09:29:09 +01:00
|
|
|
private readonly linesRepository: ObjeniousLinesRepository,
|
2026-04-07 13:20:31 +02:00
|
|
|
private readonly objeniousRepository: ObjeniousOperationsRepository
|
2026-03-24 17:27:52 +01:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 09:29:09 +01:00
|
|
|
|
|
|
|
|
private async saveLines(lines: ObjeniousLine[]) {
|
|
|
|
|
const linesToCreate = lines.map(lineToCreateLineDto)
|
|
|
|
|
let created: number[] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const line of linesToCreate) {
|
|
|
|
|
// Si es lento pasar a Promise.all
|
|
|
|
|
const res = await this.linesRepository.insertOrUpdate(line)
|
|
|
|
|
if (res?.id != undefined)
|
|
|
|
|
created.push(res.id)
|
2026-03-24 17:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async loadLines() {
|
2026-03-26 09:29:09 +01:00
|
|
|
console.log("[i] Iniciando task de volcado de lineas de Objenious")
|
|
|
|
|
// Carga todas las lineas en memoria, hay que comprobar que no se gaste demasiada
|
|
|
|
|
|
2026-04-07 13:20:31 +02:00
|
|
|
const linesIterator = this.objeniousRepository.getLinesByStatusAPI({
|
|
|
|
|
pageSize: 100
|
|
|
|
|
})
|
2026-03-26 09:29:09 +01:00
|
|
|
let lines = await linesIterator.next()
|
|
|
|
|
|
|
|
|
|
if (lines.value.error != undefined || lines.value.data == undefined) {
|
|
|
|
|
console.error("[x] Error cargando las lineas a volcar", lines.value.error)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.saveLines(lines.value.data)
|
|
|
|
|
|
|
|
|
|
while (!lines.done) {
|
|
|
|
|
lines = await linesIterator.next()
|
|
|
|
|
if (lines.value.error != undefined || lines.value.data == undefined) {
|
|
|
|
|
console.error("[x] Error cargando las lineas a volcar", lines.value.error)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await this.saveLines(lines.value.data)
|
|
|
|
|
}
|
2026-03-24 17:27:52 +01:00
|
|
|
|
2026-03-26 09:29:09 +01:00
|
|
|
console.log("[i] Terminado task de volcado de lineas de Objenious")
|
2026-03-24 17:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|