Create deployment script and cron trigger configuration
epic-scenario-based-follow-up-prompts-infrastructure-task-007 — Write the Supabase Edge Function deployment script (deploy.sh or Makefile target) that deploys the function with correct environment variable injection. Configure the pg_cron or Supabase cron trigger for default hourly invocation with a configurable schedule. Document the deployment steps, required secrets setup, and how to adjust the cron frequency per environment.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Use the Supabase CLI `supabase functions deploy` command with `--project-ref` flag controlled by the `--env` argument. Store project refs in the script as constants (`STAGING_REF`, `PRODUCTION_REF`). For the pg_cron trigger, create a migration that: (1) enables `pg_cron` extension if not already enabled; (2) creates a `scheduler_config` table with a `cron_schedule` column defaulting to `'0 * * * *'`; (3) creates the cron job reading its schedule from this table. This pattern allows ops to `UPDATE scheduler_config SET cron_schedule = '*/30 * * * *'` without running a migration.
Use `supabase secrets set --env-file .env.staging` for staging secret injection. Include a `--dry-run` flag that prints all steps without executing them.
Testing Requirements
Manual validation checklist (to be consumed by task-008): (1) run `deploy.sh --env staging` on a clean machine with only supabase CLI installed — confirm it deploys without errors; (2) confirm the pg_cron job appears in `cron.job` table with correct schedule; (3) manually trigger the cron job with `SELECT cron.run_job(job_id)` and confirm the Edge Function logs appear in Supabase Dashboard → Edge Functions → Logs; (4) change the schedule in the configuration table and confirm the next execution uses the new schedule without redeployment. No automated tests are written for the deployment script itself — coverage is provided by the integration test suite in task-008.
Supabase Edge Functions on Deno can have cold-start latency of 500ms–2s. If the evaluation window contains many activities (e.g., post-holiday catch-up), the function may approach the 60-second invocation timeout before completing all evaluations.
Mitigation & Contingency
Mitigation: Implement pagination in the activity fetch query with a configurable page size; process pages sequentially and commit history records per page so partial runs are recoverable on the next invocation.
Contingency: If timeout remains an issue at scale, split the evaluation into per-chapter invocations triggered by a fan-out pattern using Supabase Realtime or a lightweight queue.
Supabase cron triggers (pg_cron or Edge Function schedules) may miss invocations during platform maintenance windows, causing evaluation gaps that delay time-sensitive prompts beyond their intended delivery window.
Mitigation & Contingency
Mitigation: Configure the look-back window to be 2× the cron interval (e.g., 2-hour look-back for hourly cron) so a single missed invocation does not result in missed prompts; log each run's look-back range for auditability.
Contingency: If missed invocations are detected via monitoring alerts, implement a manual re-trigger endpoint accessible to admins that runs the evaluation for a specified time range.