Created
December 6, 2015 00:21
-
-
Save djpate/fadc84fb59316c7d6ed6 to your computer and use it in GitHub Desktop.
Sharded Sidekiq Webui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REDIS_A = ConnectionPool.new { Redis.new(:db => 1) } | |
REDIS_B = ConnectionPool.new { Redis.new(:db => 2) } | |
class ShardedWeb < Sidekiq::Web | |
before do | |
desired_shard = params[:shard] || request.cookies['sidekiq_shard'] | |
if desired_shard | |
Thread.current[:sidekiq_via_pool] = Object.const_get(desired_shard) | |
#this prevents us from having to override all links in the web ERBs | |
response.set_cookie 'sidekiq_shard', desired_shard | |
end | |
end | |
after do | |
Thread.current[:sidekiq_via_pool] = nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sidekiq | |
def self.redis_pool | |
Thread.current[:sidekiq_via_pool] ? Thread.current[:sidekiq_via_pool] : pool_no_shard | |
end | |
def self.pool_no_shard | |
@redis ||= Sidekiq::RedisConnection.create | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment