fix(events): refresh saved payout calendars once per hourly pass (WealthLedger/backend#53) (#157)
Backend verify / commits (push) Skipped
Backend verify / security (push) Successful in 1m6s
Backend verify / verify (push) Failing after 6m50s

This commit was merged in pull request #157.
This commit is contained in:
2026-11-02 23:06:14 +03:00
parent 169bee1da5
commit aeb4647fda
4 changed files with 131 additions and 2 deletions
@@ -110,6 +110,7 @@ export class CatalogEnrichmentService {
tickers?: Record<string, string>;
to: string;
},
refreshBefore?: Date,
) {
const { revision } = await this.access.local(userId);
const inputs = sourceInputs(instrumentType, uids, kinds, range);
@@ -123,6 +124,7 @@ export class CatalogEnrichmentService {
false,
kinds,
range,
refreshBefore,
);
}
const work = inputs.length
@@ -175,6 +177,7 @@ export class CatalogEnrichmentService {
tickers?: Record<string, string>;
to: string;
},
refreshBefore?: Date,
) {
const inputs = sourceInputs(instrumentType, uids, kinds, range);
const reservation = this.reservations.then(async () => {
@@ -189,7 +192,9 @@ export class CatalogEnrichmentService {
);
const policy = sourcePolicy(input.kind);
const needsRefresh = force || !row?.fetchedAt ||
(policy === 'quote' && tbankSourceNeedsRefresh('quote', row.fetchedAt, new Date()));
(policy === 'quote' && tbankSourceNeedsRefresh('quote', row.fetchedAt, new Date())) ||
// A walk reads a saved calendar once: later accounts see the new fetchedAt.
(policy === 'calendar' && refreshBefore !== undefined && row.fetchedAt < refreshBefore);
if (!needsRefresh) {
continue;
}
@@ -665,6 +670,7 @@ function sourcePolicy(kind: CatalogSource['kind']) {
) {
return 'quote';
}
if (['bond-events', 'dividends'].includes(kind)) return 'calendar';
return 'stable';
}
function producerKey(input: CatalogSource) {