> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cron Operations Guide

> PF-82 registers three pg_cron schedules. If pg_cron is unavailable, these operations can be triggered manually via SQL or the Supabase dashboard.

**Feature:** PF-82 Business Process Registry
**Last Updated:** 2026-03-17

***

## Scheduled Jobs

PF-82 registers three `pg_cron` schedules. If `pg_cron` is unavailable, these operations can be triggered manually via SQL or the Supabase dashboard.

### 1. Daily Process Discovery

* **Schedule:** `0 2 * * *` (02:00 UTC daily)
* **Function:** `pf_discover_business_processes(org_id)`
* **Purpose:** Scans `fw_automation_rules` and `fw_workflow_definitions` to discover new business processes and update existing ones.
* **Manual trigger:**
  ```sql theme={null}
  SELECT pf_discover_business_processes('YOUR_ORG_ID');
  ```

### 2. Health Refresh (Every 5 Minutes)

* **Schedule:** `*/5 * * * *`
* **Function:** `pf_refresh_process_health(org_id)`
* **Purpose:** Recalculates composite health scores for all active business processes using the 4-component formula (Success Rate, SLA Compliance, Latency, DLQ Rate).
* **Manual trigger:**
  ```sql theme={null}
  SELECT pf_refresh_process_health('YOUR_ORG_ID');
  ```

### 3. Daily Metric Snapshots

* **Schedule:** `55 23 * * *` (23:55 UTC daily)
* **Function:** `pf_snapshot_process_metrics()`
* **Purpose:** Captures daily snapshots of process health and execution metrics for trend analysis.
* **Manual trigger:**
  ```sql theme={null}
  SELECT pf_snapshot_process_metrics();
  ```

***

## Fallback: Dashboard-Based Scheduling

If `pg_cron` is not installed:

1. **Supabase Dashboard → Database → Extensions** — Enable `pg_cron`
2. Re-run the migration or manually create the schedules:
   ```sql theme={null}
   SELECT cron.schedule('pf_discover_processes_daily', '0 2 * * *',
     $$SELECT pf_discover_business_processes(id) FROM pf_organizations WHERE deleted_at IS NULL$$);
   SELECT cron.schedule('pf_refresh_health_5min', '*/5 * * * *',
     $$SELECT pf_refresh_process_health(id) FROM pf_organizations WHERE deleted_at IS NULL$$);
   SELECT cron.schedule('pf_snapshot_metrics_daily', '55 23 * * *',
     $$SELECT pf_snapshot_process_metrics()$$);
   ```

***

## Monitoring

* Check `cron.job_run_details` for execution history
* Process health changes are logged to `pf_notifications` for org admins
* Edge function `pf-refresh-health` logs to Supabase function logs with correlation IDs
