PhoenixKit.Migrations.Postgres.V42 (phoenix_kit v1.7.38)

Copy Markdown View Source

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 string
  • resource_type/0 - Returns the resource type string
  • execute/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

Summary

Functions

Rollback the V42 migration.

Run the V42 migration to add the scheduled jobs system.

Functions

down(opts)

Rollback the V42 migration.

up(opts)

Run the V42 migration to add the scheduled jobs system.