Skip to main content

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

PropertyValue
Function Namerefresh-aggregations
HTTP MethodAny (no method restriction)
AuthenticationNone (cron/internal invocation). The source code explicitly notes "Auth check removed for cron compatibility."
Required RoleNone (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

StatusCondition
500refresh_daily_stats_range RPC returned an error, or unhandled top-level exception

Behavior

  1. Computes the date range: from 7 days ago to today (inclusive), formatted as YYYY-MM-DD.
  2. Calls the refresh_daily_stats_range database RPC with p_start_date and p_end_date.
  3. The RPC recomputes aggregate statistics (e.g., call counts, durations, sentiment distributions) for all agencies across the specified date range.
  4. Returns the number of stat rows affected and the date range processed.

Database Tables / RPCs

Table / RPCOperationDescription
refresh_daily_stats_range (RPC)WriteRecomputes daily aggregated statistics for the given date range across all agencies

External APIs

None.

  • process-enrichment-queue -- Enriches call records with transcripts and analysis, which produces the data aggregated by this function
  • process-webhook-queue -- Creates call records whose metrics are aggregated by this function