Scenario Edge Function Scheduler
Component Detail
Description
Supabase Edge Function that acts as the scheduled entry point for periodic scenario evaluation. Triggered by pg_cron (or equivalent) at configurable intervals (e.g. nightly). Delegates to the scenario trigger engine for actual evaluation logic.
scenario-edge-function-scheduler
Summaries
The Scenario Edge Function Scheduler automates the routine health-check and engagement evaluation process that would otherwise require manual oversight or costly human coordination. By running on a configurable nightly schedule, it ensures every active peer mentor is evaluated consistently and on time — eliminating missed outreach opportunities and reducing the risk of mentor churn going undetected. This automation directly supports retention goals, protects revenue tied to peer mentor programme participation, and reduces operational overhead by removing the need for staff to manually trigger evaluation cycles. The result is a more responsive, lower-cost support model that scales with user growth without proportional staffing increases.
This component represents a medium-complexity backend delivery unit with a well-defined scope: scheduled invocation, iteration over active users, delegation to the trigger engine, and result logging. Its primary dependency is the scenario-trigger-engine, which must be completed and tested before integration work on this scheduler begins — making sequencing a key scheduling risk. Deployment depends on Supabase Edge Function infrastructure being in place and pg_cron configured correctly in the target environment. Testing requires a staging cron environment or mock invocation harness.
Observability logging must be validated as part of acceptance criteria. Plan for one sprint of development plus dedicated integration testing with the trigger engine before sign-off.
Implemented as a Supabase Edge Function, this scheduler serves as the cron-triggered entry point for the scenario evaluation pipeline. It exposes `handleScheduledInvocation()` as the function handler, which calls `fetchActivePeerMentors()` to retrieve eligible user IDs from the database, then passes them to `runEvaluationBatch(userIds)` which delegates to the scenario-trigger-engine for actual logic. Results and errors are persisted via `logRunResult(result)` for observability. The function must be stateless and idempotent — safe to re-run if the cron fires twice.
Error handling should catch partial batch failures without aborting the entire run. Configuration is injected at startup via scenario-evaluation-config. Deploy via Supabase CLI; environment variables control schedule and batch size.
Responsibilities
- Accept scheduled invocation from Supabase cron
- Iterate over all active peer mentors requiring evaluation
- Invoke the trigger engine for each applicable scenario type
- Log run results and errors for observability
Interfaces
handleScheduledInvocation()
fetchActivePeerMentors()
runEvaluationBatch(userIds)
logRunResult(result)
Relationships
Used Integrations (1)
External integrations and APIs this component relies on