Class: Julewire::Core::Execution::Handle
- Inherits:
-
Object
- Object
- Julewire::Core::Execution::Handle
- Defined in:
- lib/julewire/core/execution/handle.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #finish(reason: :closed, fields: {}, attributes: {}, error: nil, severity: nil) ⇒ Object
-
#initialize(scope:, on_finish:, on_finish_failure:) ⇒ Handle
constructor
A new instance of Handle.
- #run ⇒ Object
- #snapshot ⇒ Object
- #with_context ⇒ Object
Constructor Details
#initialize(scope:, on_finish:, on_finish_failure:) ⇒ Handle
Returns a new instance of Handle.
7 8 9 10 11 12 13 |
# File 'lib/julewire/core/execution/handle.rb', line 7 def initialize(scope:, on_finish:, on_finish_failure:) @scope = scope @on_finish = on_finish @on_finish_failure = on_finish_failure @mutex = Mutex.new @finished = false end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
15 16 17 |
# File 'lib/julewire/core/execution/handle.rb', line 15 def scope @scope end |
Instance Method Details
#finish(reason: :closed, fields: {}, attributes: {}, error: nil, severity: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/julewire/core/execution/handle.rb', line 35 def finish(reason: :closed, fields: {}, attributes: {}, error: nil, severity: nil) return false unless mark_finished add_completion_attributes(reason) @scope.add_summary(fields) unless fields.empty? @scope.add_summary_attributes(attributes) unless attributes.empty? @scope.finish_owned(error: error, severity: severity) call_finish true rescue StandardError => e report_finish_failure(e) false end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/julewire/core/execution/handle.rb', line 19 def run active_exception = nil ContextStore.current.with_scope(@scope) do yield self end rescue Exception => e # rubocop:disable Lint/RescueException active_exception = e raise ensure finish(reason: :error, error: active_exception) if active_exception end |
#snapshot ⇒ Object
17 |
# File 'lib/julewire/core/execution/handle.rb', line 17 def snapshot = View.new(@scope) |
#with_context ⇒ Object
31 32 33 |
# File 'lib/julewire/core/execution/handle.rb', line 31 def with_context(&) ContextStore.current.with_scope(@scope, &) end |