Refresh Aggregations
Background worker function invoked on a schedule (cron) that recomputes daily statistics aggregations for the trailing 7-day window. This ensures dashboard metrics stay current as new call data is processed and enriched.
Endpoint
| Property | Value |
|---|---|
| Function Name | refresh-aggregations |
| HTTP Method | Any (no method restriction) |
| Authentication | None (cron/internal invocation). The source code explicitly notes "Auth check removed for cron compatibility." |
| Required Role | None (cron) |
Request
Headers
No headers are required. This function is designed to be invoked by a Supabase cron scheduler or internal trigger without user authentication.
Body
No request body is expected. The date range is computed automatically.
Response
Success (200)
{
"rows_affected": 42,
"start_date": "2025-03-08",
"end_date": "2025-03-15"
}
Error Responses
| Status | Condition |
|---|---|
| 500 | refresh_daily_stats_range RPC returned an error, or unhandled top-level exception |
Behavior
- Computes the date range: from 7 days ago to today (inclusive), formatted as
YYYY-MM-DD. - Calls the
refresh_daily_stats_rangedatabase RPC withp_start_dateandp_end_date. - The RPC recomputes aggregate statistics (e.g., call counts, durations, sentiment distributions) for all agencies across the specified date range.
- Returns the number of stat rows affected and the date range processed.
Database Tables / RPCs
| Table / RPC | Operation | Description |
|---|---|---|
refresh_daily_stats_range (RPC) | Write | Recomputes daily aggregated statistics for the given date range across all agencies |
External APIs
None.
Related Functions
process-enrichment-queue-- Enriches call records with transcripts and analysis, which produces the data aggregated by this functionprocess-webhook-queue-- Creates call records whose metrics are aggregated by this function