Skip to content

Commit

Permalink
Drop support for classic autoloading
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcgibbon committed May 5, 2022
1 parent 812d8e5 commit 2845fce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ take a look at the [Active Job documentation][active-job-docs].
[async-adapter]: https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/AsyncAdapter.html
[active-job-docs]: https://guides.rubyonrails.org/active_job_basics.html#setting-the-backend


### Autoloading

The Maintenance Tasks framework does not support autoloading in `:classic` mode.
Please ensure your application is using [Zeitwerk](https://github.com/fxn/zeitwerk) to load your code.
For more information, please consult the [Rails guides on autoloading and reloading constants](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html).

## Usage

### Creating a Task
Expand Down
16 changes: 3 additions & 13 deletions lib/maintenance_tasks/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,19 @@ class Engine < ::Rails::Engine

initializer "maintenance_tasks.warn_classic_autoloader" do
unless Rails.autoloaders.zeitwerk_enabled?
ActiveSupport::Deprecation.warn(<<~MSG.squish)
Autoloading in classic mode is deprecated and support will be removed in the next
release of Maintenance Tasks. Please use Zeitwerk to autoload your application.
raise <<~MSG.squish
Autoloading in classic mode is not supported.
Please use Zeitwerk to autoload your application.
MSG
end
end

initializer "maintenance_tasks.eager_load_for_classic_autoloader" do
eager_load! unless Rails.autoloaders.zeitwerk_enabled?
end

initializer "maintenance_tasks.configs" do
MaintenanceTasks.backtrace_cleaner = Rails.backtrace_cleaner
end

config.to_prepare do
_ = TaskJobConcern # load this for JobIteration compatibility check
unless Rails.autoloaders.zeitwerk_enabled?
tasks_module = MaintenanceTasks.tasks_module.underscore
Dir["#{Rails.root}/app/tasks/#{tasks_module}/*.rb"].each do |file|
require_dependency(file)
end
end
end

config.after_initialize do
Expand Down
5 changes: 0 additions & 5 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")

if ENV["CLASSIC_AUTOLOADER"].present?
puts "=> Using classic autoloader"
config.autoloader = :classic
end

config.to_prepare do
MaintenanceTasks.job = "CustomTaskJob"
end
Expand Down

0 comments on commit 2845fce

Please sign in to comment.