Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Enqueue jobs inside a connected_to block

Open
#369 46 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rails, ruby
Domain
backend, database

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rails/solid_queue

All issues in rails/solid_queue

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.