Enqueue jobs inside a connected_to block
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by reviewing the database.yml configuration and config/initializers/database.rb, then reproduce SomeJob.perform_later inside the ActiveRecord::Base.connected_to block. Trace how SolidQueue chooses its database connection; done means jobs enqueue through the queue database even when the caller is connected to secondary_shard.
Written by the indexing model from the issue text.
Description
My rails application connects to multiple databases with the configs below:
database.yml
production:
primary_shard:
...
secondary_shard:
...
queue:
...
config/initializers/database.rb
# This is needed due to us using another gem whose model writes to both primary_shard and secondary_shard and its model inherits from ActiveRecord::Base
ActiveRecord::Base.instance_eval do
connects_to shards: {
primary_shard: {
writing: :primary_shard,
},
secondary_shard: {
writing: :secondary_shard,
},
}
end
SolidQueue has been working well, the only time where we cannot enqueue is if we have a block of code like below:
ActiveRecord::Base.connected_to(role: :writing, shard: :secondary_shard) do
# ...
SomeJob.perform_later(some_argument)
# ...
end
I think it is because SolidQueue is trying to insert the job into secondary_shard instead of the queue database. Is there any way to circumvent this besides rewriting the code to call perform_later outside of the connected_to block? SomeJob.perform_later might be called inside a function with the connected_to block so it's quite a big refactor for us.
- Dominant language
- Ruby
- Stars
- 2.5k
- Forks
- 250
- Avg merge
- 8h 31m
- Merged PRs (30d)
- 5
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rails/solid_queue
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
rails/solid_queue#804 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
rails/solid_queue#802 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rails/solid_queue#797 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
rails/solid_queue#792 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
rails/solid_queue#780 ·
All issues in rails/solid_queue
Similar issues
-
SyncEm always forwards a dummy block, so wrapped methods lose their no-block/Enumerator behavior Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
endoflife-date/endoflife.date#11086 ·
-
internal
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Kong/developer.konghq.com#7322 ·
-
bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100