Skip to content

refactor: Push run_at / name defaulting into JobPreparer#104

Draft
CelticMajora wants to merge 1 commit intomainfrom
donoho/require-run-at-and-name
Draft

refactor: Push run_at / name defaulting into JobPreparer#104
CelticMajora wants to merge 1 commit intomainfrom
donoho/require-run-at-and-name

Conversation

@CelticMajora
Copy link
Copy Markdown

The before_save :set_default_run_at, :set_name callback is magical and doesn't actually prevent anyone from adding a new before_save that skips callbacks. Move the defaulting into Delayed::Backend::JobPreparer so both the single save path and any future bulk-insert path pick up defaults from the same place, and delete the before_save wiring along with the Job#set_name and Base#set_default_run_at helpers.

Add db/migrate/8_require_run_at_and_name.rb to enforce the invariant at the DB level (with a COALESCE backfill for any legacy NULL rows). Direct Delayed::Job.create! / .save without supplying run_at and name is now a DB-level NOT NULL violation -- callers should route through Delayed::Job.enqueue (which runs JobPreparer).

Breaking change for anyone reaching past the documented enqueue API.

Per Nathan's PR #103 review, the before_save :set_default_run_at,
:set_name callback is magical and doesn't actually prevent anyone
from adding a new before_save that skips callbacks. Move the
defaulting into Delayed::Backend::JobPreparer so both the single
save path and any future bulk-insert path pick up defaults from
the same place, and delete the before_save wiring along with the
Job#set_name and Base#set_default_run_at helpers.

Add db/migrate/8_require_run_at_and_name.rb to enforce the
invariant at the DB level (with a COALESCE backfill for any
legacy NULL rows). Direct Delayed::Job.create! / .save without
supplying run_at and name is now a DB-level NOT NULL violation --
callers should route through Delayed::Job.enqueue (which runs
JobPreparer).

Breaking change for anyone reaching past the documented enqueue
API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CelticMajora CelticMajora self-assigned this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant