Class: Julewire::Core::Execution::Scope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id: nil, execution: nil, execution_owned: false, summary_event: nil, summary_severity: nil, summary_source: nil, attributes: nil, carry: nil, context: nil, labels: nil, neutral: nil, parent: nil, started_at: nil) ⇒ Scope

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/julewire/core/execution/scope.rb', line 9

def initialize(type:, id: nil, execution: nil, execution_owned: false, summary_event: nil, # rubocop:disable Metrics/ParameterLists
               summary_severity: nil, summary_source: nil, attributes: nil, carry: nil,
               context: nil, labels: nil, neutral: nil, parent: nil, started_at: nil)
  @identity = ScopeIdentity.new(
    type: type,
    id: id,
    started_at: started_at,
    parent: parent,
    parent_reference: parent&.execution_reference_for_child
  )
  @summary_state = summary_state(summary_event, summary_severity, summary_source)
  @execution = @identity.execution_fields(execution, owned: execution_owned)
  initialize_state(context: context, attributes: attributes, labels: labels, carry: carry, neutral: neutral)
end

Instance Attribute Details

#finished_atObject (readonly)

Returns the value of attribute finished_at.



7
8
9
# File 'lib/julewire/core/execution/scope.rb', line 7

def finished_at
  @finished_at
end

Instance Method Details

#add_field(section, fields, owned:) ⇒ Object



96
97
98
# File 'lib/julewire/core/execution/scope.rb', line 96

def add_field(section, fields, owned:)
  @fields.add(section, fields, owned: owned)
end

#add_summary(fields, owned: false) ⇒ Object



123
124
125
# File 'lib/julewire/core/execution/scope.rb', line 123

def add_summary(fields, owned: false)
  @summary_state.add(fields, owned: owned)
end

#add_summary_attributes(fields, owned: false) ⇒ Object



127
128
129
# File 'lib/julewire/core/execution/scope.rb', line 127

def add_summary_attributes(fields, owned: false)
  @summary_state.add_attributes(fields, owned: owned)
end

#add_summary_neutral(fields, owned: false) ⇒ Object



131
132
133
# File 'lib/julewire/core/execution/scope.rb', line 131

def add_summary_neutral(fields, owned: false)
  @summary_state.add_neutral(fields, owned: owned)
end

#append_summary(key, value) ⇒ Object



143
144
145
# File 'lib/julewire/core/execution/scope.rb', line 143

def append_summary(key, value)
  @summary_state.append(key, value)
end

#attributes_hashObject



52
# File 'lib/julewire/core/execution/scope.rb', line 52

def attributes_hash = @fields.attributes_hash

#carry_hashObject



50
# File 'lib/julewire/core/execution/scope.rb', line 50

def carry_hash = @fields.carry_hash

#context_hashObject



48
# File 'lib/julewire/core/execution/scope.rb', line 48

def context_hash = @fields.context_hash

#delete_carry(path) ⇒ Object



100
101
102
103
# File 'lib/julewire/core/execution/scope.rb', line 100

def delete_carry(path)
  path = Fields::Internal.normalize_path(path)
  @fields.delete(:carry, path)
end

#depthObject



34
# File 'lib/julewire/core/execution/scope.rb', line 34

def depth = @identity.depth

#execution_hashObject



36
37
38
# File 'lib/julewire/core/execution/scope.rb', line 36

def execution_hash
  Fields::FieldSet.deep_dup_owned(frozen_execution_hash)
end

#field_hash(section) ⇒ Object



62
63
64
# File 'lib/julewire/core/execution/scope.rb', line 62

def field_hash(section)
  @fields.field_hash(section)
end

#field_stack(section) ⇒ Object



66
67
68
# File 'lib/julewire/core/execution/scope.rb', line 66

def field_stack(section)
  @fields.field_stack(section)
end

#field_stacksObject



56
# File 'lib/julewire/core/execution/scope.rb', line 56

def field_stacks = @fields.stacks

#finish_owned(error: nil, severity: nil, finished_at: Time.now.utc) ⇒ Object



161
162
163
164
165
166
167
168
169
# File 'lib/julewire/core/execution/scope.rb', line 161

def finish_owned(error: nil, severity: nil, finished_at: Time.now.utc)
  # The first completion snapshot wins; later finish calls are no-ops.
  return owned_summary_record_input if finished?

  record_error(error, severity: severity) if error
  @finished_at = frozen_time(finished_at)
  @summary_state.record_duration(((monotonic_time - @identity.started_monotonic) * 1000).round(3))
  @summary_state.finalize_record_input(**summary_record_fields(timestamp: @finished_at))
end

#finished?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/julewire/core/execution/scope.rb', line 157

def finished?
  !finished_at.nil?
end

#frozen_execution_hashObject



40
41
42
# File 'lib/julewire/core/execution/scope.rb', line 40

def frozen_execution_hash
  @frozen_execution_hash ||= @identity.frozen_execution_hash(@execution)
end

#frozen_labels_hashObject



60
# File 'lib/julewire/core/execution/scope.rb', line 60

def frozen_labels_hash = @fields.frozen_labels_hash

#idObject



24
# File 'lib/julewire/core/execution/scope.rb', line 24

def id = @identity.id

#increment_summary(key, by: 1) ⇒ Object



139
140
141
# File 'lib/julewire/core/execution/scope.rb', line 139

def increment_summary(key, by: 1)
  @summary_state.increment(key, by: by)
end

#increment_summary_attribute(path, by: 1) ⇒ Object



135
136
137
# File 'lib/julewire/core/execution/scope.rb', line 135

def increment_summary_attribute(path, by: 1)
  @summary_state.increment_attribute(path, by: by)
end

#inheritable_execution_hashObject



44
45
46
# File 'lib/julewire/core/execution/scope.rb', line 44

def inheritable_execution_hash
  Fields::FieldSet.deep_dup_owned(@execution)
end

#labels_hashObject



58
# File 'lib/julewire/core/execution/scope.rb', line 58

def labels_hash = @fields.labels_hash

#lineageObject



30
# File 'lib/julewire/core/execution/scope.rb', line 30

def lineage = @identity.lineage

#measure_summary(key) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/julewire/core/execution/scope.rb', line 78

def measure_summary(key)
  measurement = @summary_state.measurement(key)
  started = monotonic_time
  begin
    yield
  ensure
    @summary_state.record_measurement(measurement, ((monotonic_time - started) * 1000).round(3))
  end
end

#measure_summary_start(key) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/julewire/core/execution/scope.rb', line 88

def measure_summary_start(key)
  measurement = @summary_state.measurement(key)
  started = monotonic_time
  MeasurementHandle.new do
    @summary_state.record_measurement(measurement, ((monotonic_time - started) * 1000).round(3))
  end
end

#metrics_hashObject



74
75
76
# File 'lib/julewire/core/execution/scope.rb', line 74

def metrics_hash
  @summary_state.metrics_hash
end

#neutral_hashObject



54
# File 'lib/julewire/core/execution/scope.rb', line 54

def neutral_hash = @fields.neutral_hash

#non_standard_exception?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/julewire/core/execution/scope.rb', line 175

def non_standard_exception?
  @summary_state.non_standard_exception?
end

#owned_summary_record_inputObject



151
152
153
154
155
# File 'lib/julewire/core/execution/scope.rb', line 151

def owned_summary_record_input
  @summary_state.owned_record_input(
    **summary_record_fields(timestamp: frozen_time(Time.now.utc))
  )
end

#parentObject



32
# File 'lib/julewire/core/execution/scope.rb', line 32

def parent = @identity.parent

#record_error(error, severity: nil) ⇒ Object



171
172
173
# File 'lib/julewire/core/execution/scope.rb', line 171

def record_error(error, severity: nil)
  @summary_state.record_error(error, severity: severity)
end

#started_atObject



28
# File 'lib/julewire/core/execution/scope.rb', line 28

def started_at = @identity.started_at

#summary_hashObject



70
71
72
# File 'lib/julewire/core/execution/scope.rb', line 70

def summary_hash
  @summary_state.payload_hash
end

#summary_record_inputObject



147
148
149
# File 'lib/julewire/core/execution/scope.rb', line 147

def summary_record_input
  @summary_state.record_input(**summary_record_fields(timestamp: frozen_time(Time.now.utc)))
end

#typeObject



26
# File 'lib/julewire/core/execution/scope.rb', line 26

def type = @identity.type

#with_carry(fields = nil, owned: false, **keyword_fields) ⇒ Object



113
114
115
# File 'lib/julewire/core/execution/scope.rb', line 113

def with_carry(fields = nil, owned: false, **keyword_fields, &)
  with_field(:carry, fields, owned: owned, **keyword_fields, &)
end

#with_context(fields = nil, owned: false, **keyword_fields) ⇒ Object



109
110
111
# File 'lib/julewire/core/execution/scope.rb', line 109

def with_context(fields = nil, owned: false, **keyword_fields, &)
  with_field(:context, fields, owned: owned, **keyword_fields, &)
end

#with_field(section, fields, owned: false, **keyword_fields) ⇒ Object



105
106
107
# File 'lib/julewire/core/execution/scope.rb', line 105

def with_field(section, fields, owned: false, **keyword_fields, &)
  @fields.with(section, fields, owned: owned, **keyword_fields, &)
end

#without_carry(path) ⇒ Object

Raises:

  • (ArgumentError)


117
118
119
120
121
# File 'lib/julewire/core/execution/scope.rb', line 117

def without_carry(path, &)
  raise ArgumentError, "carry path is required" if Fields::Internal.normalize_path(path).empty?

  @fields.without(:carry, path, &)
end