Skip to content

Adopt active_job.enqueue_after_transaction_commit = :default (currently overridden to :never) #1296

Description

@philayres

Background

As part of the Rails 8 upgrade (#1015), advancing config.load_defaults to 7.2 adopts the Rails 7.2 default:

  • active_job.enqueue_after_transaction_commit = :default

With :default, the queue adapter decides whether perform_later is deferred until after the surrounding Active Record transaction commits.

Why this is temporarily overridden

This app uses the :delayed_job adapter in test and production, and :inline in development (config/environments/*.rb). delayed_job stores jobs in the same database as Active Record, so its deferral behaviour under :default differs from adapters that use a separate queue — and development (:inline) differs again.

delayed_job commit-timing is difficult to reproduce faithfully in RSpec (specs typically run inside a rolled-back transaction and/or execute jobs inline), so a regression around enqueue-vs-commit ordering (e.g. a background job reading a record that is not yet committed) would not reliably surface in the suite.

To keep behaviour attributable and matching the pre-7.2 semantics (jobs enqueued immediately, not deferred), we have explicitly pinned:

# config/application.rb
config.active_job.enqueue_after_transaction_commit = :never

Goal

Remove the override and adopt the Rails 7.2 default (:default) once we have validated commit-dependent background jobs behave correctly with delayed_job in a realistic (staging) environment.

Acceptance criteria

  • Enumerate background jobs that depend on committed record state (e.g. Redcap capture jobs, save-trigger notify/background jobs).
  • Validate enqueue timing for those jobs against delayed_job in a realistic environment (staging), not just RSpec.
  • Add whatever spec coverage is feasible for enqueue-after-commit semantics.
  • Remove the enqueue_after_transaction_commit = :never override from config/application.rb.
  • Full RSpec suite green with the default enabled.

Refs #1015

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions