Module: ActiveRecordDeadlockHandler::Callbacks
- Defined in:
- lib/active_record_deadlock_handler/callbacks.rb
Class Method Summary collapse
- .clear ⇒ Object
-
.register {|exception, attempt, config| ... } ⇒ Object
Register a callback to be invoked on each deadlock detection.
-
.run(exception:, attempt:, config:) ⇒ Object
Invokes all registered callbacks with deadlock context.
Class Method Details
.clear ⇒ Object
22 23 24 |
# File 'lib/active_record_deadlock_handler/callbacks.rb', line 22 def clear LOCK.synchronize { @handlers.clear } end |
.register {|exception, attempt, config| ... } ⇒ Object
Register a callback to be invoked on each deadlock detection.
16 17 18 19 20 |
# File 'lib/active_record_deadlock_handler/callbacks.rb', line 16 def register(&block) raise ArgumentError, "block required" unless block LOCK.synchronize { @handlers << block } end |
.run(exception:, attempt:, config:) ⇒ Object
Invokes all registered callbacks with deadlock context. Runs outside the lock so slow callbacks don’t block registration.
28 29 30 31 32 33 34 35 |
# File 'lib/active_record_deadlock_handler/callbacks.rb', line 28 def run(exception:, attempt:, config:) handlers = LOCK.synchronize { @handlers.dup } handlers.each do |handler| handler.call(exception: exception, attempt: attempt, config: config) rescue StandardError => e warn "[ActiveRecordDeadlockHandler] Callback raised an error: #{e.class}: #{e.}" end end |