Scenario Evaluation Edge Function
Component Detail
Description
Supabase Edge Function executed on a scheduled cron trigger (e.g., every hour) that invokes the Scenario Prompt Scheduler Service. Handles authentication context, error isolation, and structured logging for observability. Designed to be idempotent so retries after failure do not cause duplicate prompts.
scenario-evaluation-edge-function
Summaries
The Scenario Evaluation Edge Function is the autonomous engine that makes the platform's relationship intelligence proactive rather than reactive. Running on a scheduled cron basis, it continuously monitors member activity patterns and triggers personalized prompts at precisely the right moment — without requiring any manual intervention from chapter administrators. This automation directly reduces operational overhead on staff while increasing member engagement consistency at scale. Its idempotent design means the system is resilient to infrastructure hiccups, ensuring reliable prompt delivery without risk of spamming users during retry scenarios — protecting both the member experience and administrator confidence in the platform's reliability as a relationship management tool.
This backend-only component is the scheduled orchestration entry point for the entire scenario evaluation pipeline and sits on the critical path for end-to-end scenario feature delivery. Development requires Supabase Edge Function deployment configuration, cron schedule setup in supabase/functions/config.toml, and service role key provisioning — coordinate with the DevOps or infrastructure owner before development begins. The function cannot be fully integration-tested until the scenario-prompt-scheduler service is complete, creating a sequencing dependency. Structured logging output format must be agreed upon with the observability or monitoring team to configure alerting thresholds.
Budget time for load testing the cron trigger under realistic chapter and membership scale before production launch.
Implemented as a Deno-based Supabase Edge Function using the serve() entry point from the Supabase functions runtime. The handleScheduledTrigger handler authenticates via the SUPABASE_SERVICE_ROLE_KEY environment variable to access backend tables without RLS restrictions. It instantiates and invokes ScenarioPromptSchedulerService, capturing per-activity errors in isolated try/catch blocks so a single evaluation failure does not abort the full run — preserving idempotency across the batch. Idempotency itself is enforced by the scheduler service via prompt-history-repository deduplication, not at this function level.
logEvaluationResult emits structured JSON to stdout for ingestion by Supabase Log Drains or an external observability platform. handleError writes to stderr with context tags for alert routing. Register the cron schedule via the cron key in supabase/functions/config.toml.
Responsibilities
- Serve as the scheduled entry point for scenario evaluation
- Authenticate with service role key for backend database access
- Invoke scheduler service and capture errors per activity
- Emit structured logs for monitoring and alerting
Interfaces
serve(handler): void
handleScheduledTrigger(req: Request): Promise<Response>
logEvaluationResult(result: EvaluationSummary): void
handleError(error: Error, context: string): void
Relationships
Related Data Entities (2)
Data entities managed by this component
Used Integrations (1)
External integrations and APIs this component relies on