Skip to content

config.active_job.default_page_size Rails config not applied #294

@willtcarey

Description

@willtcarey

Trying to set config.active_job.default_page_size somewhere in the Rails application config doesn't appear to actually set the default inside of this gem's ActiveJob extension.

Mission control extends ActiveJob::Base with a new default_page_size class attribute in an initializer:

initializer "mission_control-jobs.active_job.extensions" do
ActiveSupport.on_load :active_job do
include ActiveJob::Querying
include ActiveJob::Executing
include ActiveJob::Failed
ActiveJob.extend ActiveJob::Querying::Root
end
end

This on load callback is registered and unfortunately runs after ActiveJob's own on load callback
https://github.com/rails/rails/blob/90a1eaa1b30ba1f2d524e197460e549c03cf5698/activejob/lib/active_job/railtie.rb#L49-L75

ActiveJob tries to apply it's config twice, after initialize and as an on load callback. However, the on load callback is the only one that tries to set attributes on ActiveJob::Base (which is where the default_page_size attribute is registered). When the ActiveJob on load runs, ActiveJob hasn't been extended with the Querying interface which includes default_page_size, and when the after_initialize runs we're not trying to set options on ActiveJob::Base.

Because of the out of order loading of code and registering of callbacks, we don't see the config.active_job.default_page_size option ever actually applied to ActiveJob.

Workaround

My current workaround is adding my own callback to my config/application.rb

config.after_initialize do
  ActiveSupport.on_load(:active_job) do
    self.default_page_size = 50
  end
end

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