PhoenixKit V42 Migration: Universal Scheduled Jobs System
This migration introduces a centralized scheduled jobs system that can handle any type of scheduled task (posts, emails, notifications, etc.) using a polymorphic design with behaviour-based handlers.
Changes
Scheduled Jobs Table (phoenix_kit_scheduled_jobs)
- Universal job scheduling with polymorphic resource references
- Handler module storage for dynamic dispatch
- Status tracking (pending, executed, failed, cancelled)
- Retry support with attempt tracking
- Priority-based execution ordering
- Flexible metadata via JSONB args field
Design
The system uses a behaviour pattern where handler modules implement:
job_type/0- Returns the job type stringresource_type/0- Returns the resource type stringexecute/2- Executes the job with resource_id and args
PostgreSQL Support
- Uses binary_id primary key
- Optimized indexes for status + scheduled_at queries
- Supports prefix for schema isolation