Module: Switchman::StandardError

Defined in:
lib/switchman/standard_error.rb

Instance Method Summary collapse

Instance Method Details

#current_shard(klass = ::ActiveRecord::Base) ⇒ Object



21
22
23
# File 'lib/switchman/standard_error.rb', line 21

def current_shard(klass = ::ActiveRecord::Base)
  @active_shards&.[](klass) || Shard.default
end

#initialize(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/switchman/standard_error.rb', line 5

def initialize(*args)
  super
  # These seem to get themselves into a bad state if we try to lookup shards while processing
  return if is_a?(IO::EAGAINWaitReadable)

  return if Thread.current[:switchman_error_handler]

  begin
    Thread.current[:switchman_error_handler] = true

    @active_shards ||= Shard.active_shards
  ensure
    Thread.current[:switchman_error_handler] = nil
  end
end