> ## 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 Scheduling for Durable Execution Worker

> The FW-46 edge function workflow-executor-worker needs to be scheduled via pg_cron to process queued workflow executions.

The FW-46 edge function `workflow-executor-worker` needs to be scheduled via `pg_cron` to process queued workflow executions.

## Prerequisites

Enable extensions in the Supabase Dashboard → Extensions:

* `pg_cron`
* `pg_net`

Ensure `util.invoke_edge_function` is available and `app.settings.service_role_key` is configured in Vault.

## Scheduling SQL

Run this in the Supabase SQL Editor (NOT as a migration — it uses the `util.invoke_edge_function` helper which depends on project-specific Vault settings):

```sql theme={null}
-- Process workflow execution queue — every minute
SELECT cron.schedule(
  'process-workflow-queue',
  '* * * * *',
  $$SELECT util.invoke_edge_function('workflow-executor-worker', '{}'::jsonb);$$
);
```

> **Note:** If second-level `pg_cron` scheduling is available, use `*/10 * * * * *` (every 10 seconds) for lower latency.

## Verification

```sql theme={null}
-- Verify the job is registered
SELECT jobid, jobname, schedule, command
FROM cron.job
WHERE jobname = 'process-workflow-queue';

-- Check recent run history
SELECT jobid, job_name, status, return_message, start_time, end_time
FROM cron.job_run_details
WHERE job_name = 'process-workflow-queue'
ORDER BY start_time DESC
LIMIT 20;
```

## Managing the Cron Job

```sql theme={null}
-- List all scheduled jobs
SELECT * FROM cron.job;

-- Pause the worker (unschedule)
SELECT cron.unschedule('process-workflow-queue');

-- Re-enable after pause
SELECT cron.schedule(
  'process-workflow-queue',
  '* * * * *',
  $$SELECT util.invoke_edge_function('workflow-executor-worker', '{}'::jsonb);$$
);
```

## Troubleshooting

| Symptom                          | Check                                                                                  |
| -------------------------------- | -------------------------------------------------------------------------------------- |
| Job not running                  | `SELECT * FROM cron.job WHERE jobname = 'process-workflow-queue';` — is it registered? |
| Job runs but worker does nothing | Check `fw_module_settings.fw_execution_worker_enabled` — is any org enabled?           |
| Worker skips orgs                | Check `fw_module_settings.worker_running` — stuck semaphore? Reset with runbook.       |
| Edge function errors             | Check Edge Function logs in Supabase Dashboard.                                        |

## Related Docs

* [FW-46 Admin Guide](../fw/durable-execution-worker-admin-guide.md)
* [FW-46 Runbook](../fw/durable-execution-worker-runbook.md)
* [PF-36 Cron Scheduling](cron-scheduling-pf-36.md) — similar pattern reference
