Module: Isolator

Extended by:
Callbacks, Isolate
Defined in:
lib/isolator.rb,
lib/isolator/errors.rb,
lib/isolator/isolate.rb,
lib/isolator/railtie.rb,
lib/isolator/version.rb,
lib/isolator/notifier.rb,
lib/isolator/callbacks.rb,
lib/isolator/adapters/base.rb,
lib/isolator/configuration.rb,
lib/isolator/simple_hashie.rb,
lib/isolator/adapter_builder.rb,
lib/isolator/ext/thread_fetch.rb,
lib/isolator/orm_adapters/active_support_subscriber.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: ActiveSupportSubscriber, AdapterBuilder, Adapters, Callbacks, Isolate, ThreadFetch Classes: BackgroundJobError, Configuration, HTTPError, MailerError, Notifier, Railtie, SimpleHashie, UnsafeOperationError

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Methods included from Callbacks

after_isolate, after_isolate_callbacks, before_isolate, before_isolate_callbacks, finish!, start!

Methods included from Isolate

isolate

Class Method Details

.adaptersObject



102
103
104
# File 'lib/isolator.rb', line 102

def adapters
  @adapters ||= Isolator::SimpleHashie.new
end

.clear_transactions!Object



86
87
88
# File 'lib/isolator.rb', line 86

def clear_transactions!
  Thread.current[:isolator_transactions] = 0
end

.configObject



20
21
22
# File 'lib/isolator.rb', line 20

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



24
25
26
# File 'lib/isolator.rb', line 24

def configure
  yield config
end

.decr_transactions!Object



80
81
82
83
84
# File 'lib/isolator.rb', line 80

def decr_transactions!
  Thread.current[:isolator_transactions] =
    Thread.current.fetch(:isolator_transactions) - 1
  finish! if Thread.current.fetch(:isolator_transactions) == (transactions_threshold - 1)
end

.disableObject

Accepts block and disable Isolator within



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/isolator.rb', line 41

def disable
  return yield if disabled?
  res = nil
  begin
    disable!
    res = yield
  ensure
    enable!
  end
  res
end

.disable!Object



36
37
38
# File 'lib/isolator.rb', line 36

def disable!
  Thread.current[:isolator_disabled] = true
end

.disabled?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/isolator.rb', line 98

def disabled?
  Thread.current[:isolator_disabled] == true
end

.enableObject

Accepts block and enable Isolator within



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/isolator.rb', line 54

def enable
  return yield if enabled?
  res = nil
  begin
    enable!
    res = yield
  ensure
    disable!
  end
  res
end

.enable!Object



32
33
34
# File 'lib/isolator.rb', line 32

def enable!
  Thread.current[:isolator_disabled] = false
end

.enabled?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/isolator.rb', line 94

def enabled?
  !disabled?
end

.incr_transactions!Object



74
75
76
77
78
# File 'lib/isolator.rb', line 74

def incr_transactions!
  Thread.current[:isolator_transactions] =
    Thread.current.fetch(:isolator_transactions, 0) + 1
  start! if Thread.current.fetch(:isolator_transactions) == transactions_threshold
end

.notify(exception:, backtrace:) ⇒ Object



28
29
30
# File 'lib/isolator.rb', line 28

def notify(exception:, backtrace:)
  Notifier.new(exception, backtrace).call
end

.transactions_thresholdObject



66
67
68
# File 'lib/isolator.rb', line 66

def transactions_threshold
  Thread.current.fetch(:isolator_threshold)
end

.transactions_threshold=(val) ⇒ Object



70
71
72
# File 'lib/isolator.rb', line 70

def transactions_threshold=(val)
  Thread.current[:isolator_threshold] = val
end

.within_transaction?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/isolator.rb', line 90

def within_transaction?
  Thread.current.fetch(:isolator_transactions, 0) >= transactions_threshold
end