aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-04-09 15:24:08 -0400
committerGitHub <noreply@github.com>2019-04-09 15:24:08 -0400
commitd5f2deb1539927c8793588e7d1e86d84211d4da8 (patch)
tree9eb9903254b425e502db518f1f8425ed6d8dd0b4 /railties
parentdd58d040b2b798105b95e21396e86266bfd40de9 (diff)
parent75811c37a9c1cc7d6977cd841437d136d4b95440 (diff)
downloadrails-d5f2deb1539927c8793588e7d1e86d84211d4da8.tar.gz
rails-d5f2deb1539927c8793588e7d1e86d84211d4da8.tar.bz2
rails-d5f2deb1539927c8793588e7d1e86d84211d4da8.zip
Merge pull request #35905 from BatedUrGonnaDie/dont-override-job-seed-adapter
Only override async adapter when seeding
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/engine.rb8
-rw-r--r--railties/test/railties/engine_test.rb15
3 files changed, 25 insertions, 2 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index c5136b7ab0..ab400e5982 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Only force `:async` ActiveJob adapter to `:inline` during seeding.
+
+ *BatedUrGonnaDie*
+
* The `connection` option of `rails dbconsole` command is deprecated in
favor of `database` option.
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 778bbebe75..eb2f0e8fca 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -550,7 +550,13 @@ module Rails
# Blog::Engine.load_seed
def load_seed
seed_file = paths["db/seeds.rb"].existent.first
- with_inline_jobs { load(seed_file) } if seed_file
+ return unless seed_file
+
+ if config.active_job.queue_adapter == :async
+ with_inline_jobs { load(seed_file) }
+ else
+ load(seed_file)
+ end
end
# Add configured load paths to Ruby's load path, and remove duplicate entries.
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 69f6e34d58..fe5c62c07d 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -879,7 +879,7 @@ YAML
assert Bukkits::Engine.config.bukkits_seeds_loaded
end
- test "jobs are ran inline while loading seeds" do
+ test "jobs are ran inline while loading seeds with async adapter configured" do
app_file "db/seeds.rb", <<-RUBY
Rails.application.config.seed_queue_adapter = ActiveJob::Base.queue_adapter
RUBY
@@ -891,6 +891,19 @@ YAML
assert_instance_of ActiveJob::QueueAdapters::AsyncAdapter, ActiveJob::Base.queue_adapter
end
+ test "jobs are ran with original adapter while loading seeds with custom adapter configured" do
+ app_file "db/seeds.rb", <<-RUBY
+ Rails.application.config.seed_queue_adapter = ActiveJob::Base.queue_adapter
+ RUBY
+
+ boot_rails
+ Rails.application.config.active_job.queue_adapter = :delayed_job
+ Rails.application.load_seed
+
+ assert_instance_of ActiveJob::QueueAdapters::DelayedJobAdapter, Rails.application.config.seed_queue_adapter
+ assert_instance_of ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter
+ end
+
test "skips nonexistent seed data" do
FileUtils.rm "#{app_path}/db/seeds.rb"
boot_rails