Skip to content

Commit

Permalink
Merge pull request #4648 from nebulab/elia+kennyadsl/fix-sqlite-busy-…
Browse files Browse the repository at this point in the history
…error

Fix occasional "database is locked" errors while loading sample data
  • Loading branch information
kennyadsl authored Sep 30, 2022
2 parents af011d5 + e6763c0 commit 29da36c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sample/lib/spree_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class Engine < Rails::Engine

# Needs to be here so we can access it inside the tests
def self.load_samples
original_active_job_adapter = ActiveJob::Base.queue_adapter

# SQLite doesn't support full-concurrency and often fails with
# "SQLite3::BusyException: database is locked" when ActiveJob uses the default
# threaded `:async` adapter. ActiveJob is used by ActiveStorage to analyze uploaded
# images for metadata.
if ActiveRecord::Base.connection.adapter_name == "SQLite"
ActiveJob::Base.queue_adapter = :inline
end

Spree::Sample.load_sample("payment_methods")
Spree::Sample.load_sample("tax_categories")
Spree::Sample.load_sample("tax_rates")
Expand All @@ -27,6 +37,8 @@ def self.load_samples
Spree::Sample.load_sample("orders")
Spree::Sample.load_sample("payments")
Spree::Sample.load_sample("reimbursements")
ensure
ActiveJob::Base.queue_adapter = original_active_job_adapter
end
end
end

0 comments on commit 29da36c

Please sign in to comment.