aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBatedUrGonnaDie <batedurgonnadie@yahoo.com>2019-04-09 00:35:16 -0700
committerBatedUrGonnaDie <batedurgonnadie@yahoo.com>2019-04-09 00:35:16 -0700
commit75811c37a9c1cc7d6977cd841437d136d4b95440 (patch)
treeb92c2322bc4a32800151834c69e24c42ac808620
parent496e8ee9370e9f165fd1f5d2620296299a6a8649 (diff)
downloadrails-75811c37a9c1cc7d6977cd841437d136d4b95440.tar.gz
rails-75811c37a9c1cc7d6977cd841437d136d4b95440.tar.bz2
rails-75811c37a9c1cc7d6977cd841437d136d4b95440.zip
Only override async adapter when seeding
-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