fix: restore terminal hourly lifecycle after persistence failure (#56)
Backend verify / commits (pull_request) Successful in 33s
Backend verify / security (pull_request) Successful in 12s
Backend verify / verify (pull_request) Successful in 5m48s

This commit is contained in:
2026-10-12 20:42:19 +03:00
parent 96a442253e
commit fa57a201fd
5 changed files with 921 additions and 112 deletions
@@ -58,7 +58,7 @@ export class CatalogEnrichmentService {
private running = false;
private readonly completions = new Map<
string,
{ done: Promise<void>; resolve: () => void; workId: string }
{ attempt: TbankSyncAttempt; done: Promise<void>; resolve: () => void; workId: string }
>();
async ensureDetail(
@@ -208,7 +208,7 @@ export class CatalogEnrichmentService {
const done = new Promise<void>((finish) => {
resolve = finish;
});
this.completions.set(attemptId, { workId: id, done, resolve });
this.completions.set(attemptId, { attempt, done, resolve, workId: id });
const key = producerKey(input);
const producer = this.producers.get(key);
if (producer) producer.observers.push({ attempt, input });
@@ -580,6 +580,14 @@ export class CatalogEnrichmentService {
}
}
} catch {
// Persistence failed mid-batch: finish every still-open observer
// attempt durably so no source row is left running. Best effort — a
// row that stays open is re-reserved by the next reader.
for (const completion of this.completions.values()) {
await this.repository
.finish(completion.attempt, false)
.catch(() => undefined);
}
for (const completion of this.completions.values()) completion.resolve();
this.completions.clear();
this.active.clear();