Skip to content

Commit

Permalink
Add load hooks for SolidQueue::Record
Browse files Browse the repository at this point in the history
We can use these to point to a different database:

E.g:
```
ActiveSupport.on_load(:solid_queue_record) do
  connects_to database: { writing: :solid_queue }
end
```
  • Loading branch information
djmb committed Nov 1, 2023
1 parent 290b360 commit dcbb5db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/solid_queue/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ class Record < ActiveRecord::Base
self.abstract_class = true
end
end

ActiveSupport.run_load_hooks :solid_queue_record, SolidQueue::Record
5 changes: 5 additions & 0 deletions test/dummy/config/initializers/solid_queue_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Rails.application.config.x.solid_queue_record_hook_ran = false

ActiveSupport.on_load(:solid_queue_record) do
Rails.application.config.x.solid_queue_record_hook_ran = true
end
7 changes: 7 additions & 0 deletions test/unit/hooks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class HooksTest < ActiveSupport::TestCase
test "solid_queue_record hook ran" do
assert Rails.application.config.x.solid_queue_record_hook_ran
end
end

0 comments on commit dcbb5db

Please sign in to comment.