Module: ActiveRecord::DynamicTimeout::BaseExtension::ClassMethods
- Defined in:
- lib/active_record/dynamic_timeout/extensions/base_extension.rb
Instance Method Summary collapse
-
#current_timeout_seconds ⇒ Numeric, NilClass
The current timeout in seconds, or nil if no timeout is set.
- #timeout_isolation_scope=(scope_class) ⇒ Object
- #with_timeout(timeout_seconds) ⇒ Object
Instance Method Details
#current_timeout_seconds ⇒ Numeric, NilClass
Returns The current timeout in seconds, or nil if no timeout is set.
23 24 25 |
# File 'lib/active_record/dynamic_timeout/extensions/base_extension.rb', line 23 def current_timeout_seconds timeout_stack.last end |
#timeout_isolation_scope=(scope_class) ⇒ Object
28 29 30 31 32 |
# File 'lib/active_record/dynamic_timeout/extensions/base_extension.rb', line 28 def timeout_isolation_scope=(scope_class) (scope_class == Thread || scope_class == Fiber) or raise ArgumentError, "scope must be `Thread` or `Fiber`, got: `#{scope_class.inspect}`" raise ArgumentError, "timeout_isolation_scope can only be set once" if @timeout_isolation_scope @timeout_isolation_scope = scope_class end |
#with_timeout(timeout_seconds) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/active_record/dynamic_timeout/extensions/base_extension.rb', line 12 def with_timeout(timeout_seconds) (timeout_seconds.is_a?(Numeric) || timeout_seconds.nil?) or raise ArgumentError, "timeout_seconds must be Numeric or nil, got: `#{timeout_seconds.inspect}`" begin timeout_stack << timeout_seconds yield ensure timeout_stack.pop end end |