Skip to content

Commit d5f2deb

Browse files
authored
Merge pull request rails#35905 from BatedUrGonnaDie/dont-override-job-seed-adapter
Only override async adapter when seeding
2 parents dd58d04 + 75811c3 commit d5f2deb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Only force `:async` ActiveJob adapter to `:inline` during seeding.
2+
3+
*BatedUrGonnaDie*
4+
15
* The `connection` option of `rails dbconsole` command is deprecated in
26
favor of `database` option.
37

railties/lib/rails/engine.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,13 @@ def config
550550
# Blog::Engine.load_seed
551551
def load_seed
552552
seed_file = paths["db/seeds.rb"].existent.first
553-
with_inline_jobs { load(seed_file) } if seed_file
553+
return unless seed_file
554+
555+
if config.active_job.queue_adapter == :async
556+
with_inline_jobs { load(seed_file) }
557+
else
558+
load(seed_file)
559+
end
554560
end
555561

556562
# Add configured load paths to Ruby's load path, and remove duplicate entries.

railties/test/railties/engine_test.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def index
879879
assert Bukkits::Engine.config.bukkits_seeds_loaded
880880
end
881881

882-
test "jobs are ran inline while loading seeds" do
882+
test "jobs are ran inline while loading seeds with async adapter configured" do
883883
app_file "db/seeds.rb", <<-RUBY
884884
Rails.application.config.seed_queue_adapter = ActiveJob::Base.queue_adapter
885885
RUBY
@@ -891,6 +891,19 @@ def index
891891
assert_instance_of ActiveJob::QueueAdapters::AsyncAdapter, ActiveJob::Base.queue_adapter
892892
end
893893

894+
test "jobs are ran with original adapter while loading seeds with custom adapter configured" do
895+
app_file "db/seeds.rb", <<-RUBY
896+
Rails.application.config.seed_queue_adapter = ActiveJob::Base.queue_adapter
897+
RUBY
898+
899+
boot_rails
900+
Rails.application.config.active_job.queue_adapter = :delayed_job
901+
Rails.application.load_seed
902+
903+
assert_instance_of ActiveJob::QueueAdapters::DelayedJobAdapter, Rails.application.config.seed_queue_adapter
904+
assert_instance_of ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter
905+
end
906+
894907
test "skips nonexistent seed data" do
895908
FileUtils.rm "#{app_path}/db/seeds.rb"
896909
boot_rails

0 commit comments

Comments
 (0)