Class: Julewire::Core::Execution::Handle
- Inherits:
-
Object
- Object
- Julewire::Core::Execution::Handle
- Defined in:
- lib/julewire/core/execution/handle.rb
Instance Method Summary collapse
- #finish(reason: :closed, fields: nil, attributes: nil, 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.
9 10 11 12 13 14 |
# File 'lib/julewire/core/execution/handle.rb', line 9 def initialize(scope:, on_finish:, on_finish_failure:) @scope = scope @on_finish = on_finish @on_finish_failure = on_finish_failure @finished = Concurrent::AtomicBoolean.new end |
Instance Method Details
#finish(reason: :closed, fields: nil, attributes: nil, error: nil, severity: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/julewire/core/execution/handle.rb', line 34 def finish(reason: :closed, fields: nil, attributes: nil, error: nil, severity: nil) # Finishing is one-shot: retrying after partial summary mutation can # duplicate completion data, so failures are reported and stop here. return false unless mark_finished add_completion_attributes(reason) @scope.add_summary(fields) @scope.add_summary_attributes(attributes) @scope.finish_owned(error: error, severity: severity) call_finish true rescue StandardError => e report_finish_failure(e, phase: :summary_finish) false end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/julewire/core/execution/handle.rb', line 18 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
16 |
# File 'lib/julewire/core/execution/handle.rb', line 16 def snapshot = View.new(@scope) |
#with_context ⇒ Object
30 31 32 |
# File 'lib/julewire/core/execution/handle.rb', line 30 def with_context(&) ContextStore.current.with_scope(@scope, &) end |