Module: DispatchPolicy::Bypass

Defined in:
lib/dispatch_policy/bypass.rb

Overview

Thread-local guard. When active, ActiveJob#enqueue calls within the block bypass the dispatch_policy around_enqueue and reach the real adapter.

Constant Summary collapse

KEY =
:__dispatch_policy_bypass__

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dispatch_policy/bypass.rb', line 19

def active?
  Thread.current[KEY] == true
end

.withObject



11
12
13
14
15
16
17
# File 'lib/dispatch_policy/bypass.rb', line 11

def with
  previous = Thread.current[KEY]
  Thread.current[KEY] = true
  yield
ensure
  Thread.current[KEY] = previous
end