Class: Julewire::Core::Execution::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/core/execution/handle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#scopeObject (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

#runObject



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

#snapshotObject



17
# File 'lib/julewire/core/execution/handle.rb', line 17

def snapshot = View.new(@scope)

#with_contextObject



31
32
33
# File 'lib/julewire/core/execution/handle.rb', line 31

def with_context(&)
  ContextStore.current.with_scope(@scope, &)
end