Infrastructure medium complexity Shared Component backend
0
Dependencies
1
Dependents
0
Entities
1
Integrations

Description

Infrastructure component that schedules and triggers backend cron jobs, specifically the nightly certification expiry check. Built on Supabase Edge Functions with pg_cron or an equivalent serverless scheduler. Provides retry handling and execution logging.

Feature: Peer Mentor Pause & Status Management

nightly-scheduler

Summaries

The Nightly Job Scheduler is the operational heartbeat of the certification management program, ensuring that expired or near-expiry certifications are identified every night without manual intervention. Without reliable scheduled processing, the organization risks mentors remaining active on the website past their certification expiry — a compliance and reputational liability. By automating this check on a consistent nightly cadence, the organization shifts from reactive problem discovery to proactive risk management, catching issues before they affect families or coordinators. As a shared infrastructure component, it also reduces operational overhead by providing a single, centralized job execution platform reusable across future automated tasks.

This is a medium-complexity shared infrastructure component that underpins the certification expiry workflow. The primary delivery risk is environment-specific: Supabase pg_cron availability and configuration must be validated in the target environment before committing to this implementation path, or an alternative serverless scheduler (e.g., Supabase Edge Functions with an external cron trigger) must be scoped. Build alerting for consecutive job failures into the acceptance criteria — operations teams need visibility before production. Testing must include simulated failure scenarios and execution log validation.

Because this component is shared, its reliability directly impacts all features that register scheduled jobs, so allocate dedicated QA time for failure path coverage.

Built on Supabase Edge Functions with pg_cron or an equivalent serverless scheduler, this infrastructure component provides job registration, execution, and monitoring primitives. registerJob(jobName, cronExpression, handler) binds a named job to a schedule; triggerJob() enables manual or test-driven execution without waiting for the cron window. getLastExecutionResult() exposes structured execution metadata (status, duration, error) consumed by monitoring dashboards and alerting integrations. Implement idempotent job handlers — the scheduler should be able to retry without side effects.

Persist execution logs to a dedicated jobs table for audit and debugging. The component is shared across backend features, so use a registry pattern to avoid hardcoded job definitions and support dynamic job registration at startup.

Responsibilities

  • Register and manage scheduled cron jobs for backend tasks
  • Trigger certification-expiry-checker at configured nightly time
  • Log job execution outcomes and durations
  • Alert on consecutive job failures via monitoring integration

Interfaces

registerJob(jobName, cronExpression, handler)
triggerJob(jobName)
getLastExecutionResult(jobName)
cancelJob(jobName)
listScheduledJobs()

Relationships

Dependents (1)

Components that depend on this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/scheduler 5 endpoints
GET /api/v1/scheduler/jobs List all registered scheduler jobs
POST /api/v1/scheduler/jobs Register a new scheduler job
POST /api/v1/scheduler/jobs/:jobName/trigger Manually trigger a registered job immediately
GET /api/v1/scheduler/jobs/:jobName/last-result Get the result of the most recent execution of a job
DELETE /api/v1/scheduler/jobs/:jobName Cancel and deregister a scheduler job