fix: restore terminal hourly lifecycle after persistence failure (#56)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user