Generates an Ecto migration that registers a PgFlow job in the database.
Jobs are single-step flows under the hood. This task generates migration SQL
that creates the flow, adds the step, and marks it as flow_type = 'job'.
Usage
mix pgflow.gen.job_migration MyApp.Jobs.SendEmail
mix pgflow.gen.job_migration MyApp.Jobs.SendEmail --migrations-path priv/repo/migrationsOptions
--migrations-path- Path to the migrations directory. Defaults topriv/repo/migrations.
Generated SQL
The migration executes SQL statements that:
- Create the flow record and PGMQ queue
- Add the step (slug defaults to the job queue name, or an explicit name from
perform :name do) - Mark the flow as
flow_type = 'job'
Example generated migration:
defmodule MyApp.Repo.Migrations.CompileSendEmail do
use Ecto.Migration
def up do
execute "SELECT pgflow.create_flow('send_email', 3, 5, 60)"
execute "SELECT pgflow.add_step('send_email', 'send_email', ARRAY[]::text[], NULL, NULL, NULL, NULL, 'single')"
execute "UPDATE pgflow.flows SET flow_type = 'job' WHERE flow_slug = 'send_email'"
end
def down do
execute "DELETE FROM pgflow.deps WHERE flow_slug = 'send_email'"
execute "DELETE FROM pgflow.steps WHERE flow_slug = 'send_email'"
execute "DELETE FROM pgflow.flows WHERE flow_slug = 'send_email'"
execute "SELECT pgmq.drop_queue('send_email')"
end
endRequirements
The job module must:
- Use
PgFlow.Job - Define a valid job with
@joband aperformblock - Be compilable (no syntax errors)