Expense Aggregate Nightly Scheduler
Component Detail
Infrastructure
medium complexity
backend
1
Dependencies
0
Dependents
1
Entities
0
Integrations
Description
Scheduled background job that runs nightly to materialize expense aggregate metrics and statistical baseline values into the expense_summary_snapshots table. Reduces dashboard query latency by replacing ad-hoc aggregation over large claim datasets with simple snapshot reads supplemented by a same-day real-time delta.
expense-aggregate-scheduler
Responsibilities
- Run nightly SQL aggregation over expense_claims and expense_items grouped by organization_id and time period
- Upsert computed aggregate rows into the expense_summary_snapshots materialized table
- Compute and persist rolling average and standard deviation baselines per organization for the anomaly detection layer
- Log execution status and surface failures via existing monitoring infrastructure
Interfaces
run(): Promise<void>
aggregateForOrg(orgId: string): Promise<ExpenseSummarySnapshot>
computeBaseline(orgId: string): Promise<AnomalyBaseline>
onFailure(err: Error): void