Class: Julewire::Core::Execution::Scope
- Inherits:
-
Object
- Object
- Julewire::Core::Execution::Scope
- Defined in:
- lib/julewire/core/execution/scope.rb
Instance Attribute Summary collapse
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
Instance Method Summary collapse
- #add_field(section, fields, owned: false) ⇒ Object
- #add_summary(fields, owned: false) ⇒ Object
- #add_summary_attributes(fields, owned: false) ⇒ Object
- #add_summary_neutral(fields, owned: false) ⇒ Object
- #append_summary(key, value) ⇒ Object
- #attributes_hash ⇒ Object
- #carry_hash ⇒ Object
- #context_hash ⇒ Object
- #delete_carry(path) ⇒ Object
- #depth ⇒ Object
- #execution_hash ⇒ Object
- #field_hash(section) ⇒ Object
- #field_stack(section) ⇒ Object
- #field_stacks ⇒ Object
- #finish_owned(error: nil, severity: nil, finished_at: Time.now.utc) ⇒ Object
- #finished? ⇒ Boolean
- #frozen_execution_hash ⇒ Object
- #frozen_labels_hash ⇒ Object
- #id ⇒ Object
- #increment_summary(key, by: 1) ⇒ Object
- #increment_summary_attribute(path, by: 1) ⇒ Object
- #inheritable_execution_hash ⇒ Object
-
#initialize(type:, id: nil, execution: EMPTY_HASH, execution_owned: false, summary_event: nil, summary_severity: nil, summary_source: nil, attributes: EMPTY_HASH, carry: EMPTY_HASH, context: EMPTY_HASH, labels: EMPTY_HASH, neutral: EMPTY_HASH, parent: nil, started_at: nil) ⇒ Scope
constructor
rubocop:disable Metrics/ParameterLists.
- #labels_hash ⇒ Object
- #lineage ⇒ Object
- #measure_summary(key) ⇒ Object
- #measure_summary_start(key) ⇒ Object
- #metrics_hash ⇒ Object
- #neutral_hash ⇒ Object
- #non_standard_exception? ⇒ Boolean
- #owned_summary_record_input ⇒ Object
- #parent ⇒ Object
- #record_error(error, severity: nil) ⇒ Object
- #started_at ⇒ Object
- #summary_hash ⇒ Object
- #summary_record_input ⇒ Object
- #type ⇒ Object
- #with_carry(fields) ⇒ Object
- #with_context(fields) ⇒ Object
- #with_field(section, fields, owned: false) ⇒ Object
- #without_carry(path) ⇒ Object
Constructor Details
#initialize(type:, id: nil, execution: EMPTY_HASH, execution_owned: false, summary_event: nil, summary_severity: nil, summary_source: nil, attributes: EMPTY_HASH, carry: EMPTY_HASH, context: EMPTY_HASH, labels: EMPTY_HASH, neutral: EMPTY_HASH, parent: nil, started_at: nil) ⇒ Scope
rubocop:disable Metrics/ParameterLists
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/julewire/core/execution/scope.rb', line 12 def initialize(type:, id: nil, execution: EMPTY_HASH, execution_owned: false, summary_event: nil, # rubocop:disable Metrics/ParameterLists summary_severity: nil, summary_source: nil, attributes: EMPTY_HASH, carry: EMPTY_HASH, context: EMPTY_HASH, labels: EMPTY_HASH, neutral: EMPTY_HASH, 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_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
10 11 12 |
# File 'lib/julewire/core/execution/scope.rb', line 10 def finished_at @finished_at end |
Instance Method Details
#add_field(section, fields, owned: false) ⇒ Object
99 100 101 |
# File 'lib/julewire/core/execution/scope.rb', line 99 def add_field(section, fields, owned: false) @fields.add(section, fields, owned: owned) end |
#add_summary(fields, owned: false) ⇒ Object
127 128 129 |
# File 'lib/julewire/core/execution/scope.rb', line 127 def add_summary(fields, owned: false) @summary_state.add(fields, owned: owned) end |
#add_summary_attributes(fields, owned: false) ⇒ Object
131 132 133 |
# File 'lib/julewire/core/execution/scope.rb', line 131 def add_summary_attributes(fields, owned: false) @summary_state.add_attributes(fields, owned: owned) end |
#add_summary_neutral(fields, owned: false) ⇒ Object
135 136 137 |
# File 'lib/julewire/core/execution/scope.rb', line 135 def add_summary_neutral(fields, owned: false) @summary_state.add_neutral(fields, owned: owned) end |
#append_summary(key, value) ⇒ Object
147 148 149 |
# File 'lib/julewire/core/execution/scope.rb', line 147 def append_summary(key, value) @summary_state.append(key, value) end |
#attributes_hash ⇒ Object
55 |
# File 'lib/julewire/core/execution/scope.rb', line 55 def attributes_hash = @fields.attributes_hash |
#carry_hash ⇒ Object
53 |
# File 'lib/julewire/core/execution/scope.rb', line 53 def carry_hash = @fields.carry_hash |
#context_hash ⇒ Object
51 |
# File 'lib/julewire/core/execution/scope.rb', line 51 def context_hash = @fields.context_hash |
#delete_carry(path) ⇒ Object
103 104 105 106 |
# File 'lib/julewire/core/execution/scope.rb', line 103 def delete_carry(path) path = Fields::Internal.normalize_path(path) @fields.delete(:carry, path) end |
#depth ⇒ Object
37 |
# File 'lib/julewire/core/execution/scope.rb', line 37 def depth = @identity.depth |
#execution_hash ⇒ Object
39 40 41 |
# File 'lib/julewire/core/execution/scope.rb', line 39 def execution_hash Fields::FieldSet.deep_dup(frozen_execution_hash) end |
#field_hash(section) ⇒ Object
65 66 67 |
# File 'lib/julewire/core/execution/scope.rb', line 65 def field_hash(section) @fields.field_hash(section) end |
#field_stack(section) ⇒ Object
69 70 71 |
# File 'lib/julewire/core/execution/scope.rb', line 69 def field_stack(section) @fields.field_stack(section) end |
#field_stacks ⇒ Object
59 |
# File 'lib/julewire/core/execution/scope.rb', line 59 def field_stacks = @fields.stacks |
#finish_owned(error: nil, severity: nil, finished_at: Time.now.utc) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/julewire/core/execution/scope.rb', line 165 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
161 162 163 |
# File 'lib/julewire/core/execution/scope.rb', line 161 def finished? !finished_at.nil? end |
#frozen_execution_hash ⇒ Object
43 44 45 |
# File 'lib/julewire/core/execution/scope.rb', line 43 def frozen_execution_hash @frozen_execution_hash ||= @identity.frozen_execution_hash(@execution) end |
#frozen_labels_hash ⇒ Object
63 |
# File 'lib/julewire/core/execution/scope.rb', line 63 def frozen_labels_hash = @fields.frozen_labels_hash |
#id ⇒ Object
27 |
# File 'lib/julewire/core/execution/scope.rb', line 27 def id = @identity.id |
#increment_summary(key, by: 1) ⇒ Object
143 144 145 |
# File 'lib/julewire/core/execution/scope.rb', line 143 def increment_summary(key, by: 1) @summary_state.increment(key, by: by) end |
#increment_summary_attribute(path, by: 1) ⇒ Object
139 140 141 |
# File 'lib/julewire/core/execution/scope.rb', line 139 def increment_summary_attribute(path, by: 1) @summary_state.increment_attribute(path, by: by) end |
#inheritable_execution_hash ⇒ Object
47 48 49 |
# File 'lib/julewire/core/execution/scope.rb', line 47 def inheritable_execution_hash Fields::FieldSet.deep_dup(@execution) end |
#labels_hash ⇒ Object
61 |
# File 'lib/julewire/core/execution/scope.rb', line 61 def labels_hash = @fields.labels_hash |
#lineage ⇒ Object
33 |
# File 'lib/julewire/core/execution/scope.rb', line 33 def lineage = @identity.lineage |
#measure_summary(key) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/julewire/core/execution/scope.rb', line 81 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
91 92 93 94 95 96 97 |
# File 'lib/julewire/core/execution/scope.rb', line 91 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_hash ⇒ Object
77 78 79 |
# File 'lib/julewire/core/execution/scope.rb', line 77 def metrics_hash @summary_state.metrics_hash end |
#neutral_hash ⇒ Object
57 |
# File 'lib/julewire/core/execution/scope.rb', line 57 def neutral_hash = @fields.neutral_hash |
#non_standard_exception? ⇒ Boolean
179 180 181 |
# File 'lib/julewire/core/execution/scope.rb', line 179 def non_standard_exception? @summary_state.non_standard_exception? end |
#owned_summary_record_input ⇒ Object
155 156 157 158 159 |
# File 'lib/julewire/core/execution/scope.rb', line 155 def owned_summary_record_input @summary_state.owned_record_input( **summary_record_fields(timestamp: finished_at || frozen_time(Time.now.utc)) ) end |
#parent ⇒ Object
35 |
# File 'lib/julewire/core/execution/scope.rb', line 35 def parent = @identity.parent |
#record_error(error, severity: nil) ⇒ Object
175 176 177 |
# File 'lib/julewire/core/execution/scope.rb', line 175 def record_error(error, severity: nil) @summary_state.record_error(error, severity: severity) end |
#started_at ⇒ Object
31 |
# File 'lib/julewire/core/execution/scope.rb', line 31 def started_at = @identity.started_at |
#summary_hash ⇒ Object
73 74 75 |
# File 'lib/julewire/core/execution/scope.rb', line 73 def summary_hash @summary_state.payload_hash end |
#summary_record_input ⇒ Object
151 152 153 |
# File 'lib/julewire/core/execution/scope.rb', line 151 def summary_record_input @summary_state.record_input(**summary_record_fields(timestamp: finished_at || frozen_time(Time.now.utc))) end |
#type ⇒ Object
29 |
# File 'lib/julewire/core/execution/scope.rb', line 29 def type = @identity.type |
#with_carry(fields) ⇒ Object
116 117 118 |
# File 'lib/julewire/core/execution/scope.rb', line 116 def with_carry(fields, &) with_field(:carry, fields, &) end |
#with_context(fields) ⇒ Object
112 113 114 |
# File 'lib/julewire/core/execution/scope.rb', line 112 def with_context(fields, &) with_field(:context, fields, &) end |
#with_field(section, fields, owned: false) ⇒ Object
108 109 110 |
# File 'lib/julewire/core/execution/scope.rb', line 108 def with_field(section, fields, owned: false, &) @fields.with(section, fields, owned: owned, &) end |
#without_carry(path) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/julewire/core/execution/scope.rb', line 120 def without_carry(path, &) normalized_path = Fields::Internal.normalize_path(path) raise ArgumentError, "carry path is required" if normalized_path.empty? @fields.without(:carry, normalized_path, &) end |