Class: FiberAudit::Runtime::Lifecycle
- Inherits:
-
Object
- Object
- FiberAudit::Runtime::Lifecycle
- Defined in:
- lib/fiber_audit/runtime/lifecycle.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#active_operations ⇒ Object
readonly
Returns the value of attribute active_operations.
-
#execution_context_store ⇒ Object
readonly
Returns the value of attribute execution_context_store.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#owner_pid ⇒ Object
readonly
Returns the value of attribute owner_pid.
-
#probe_registry ⇒ Object
readonly
Returns the value of attribute probe_registry.
-
#rails_integration ⇒ Object
readonly
Returns the value of attribute rails_integration.
-
#recorder ⇒ Object
readonly
Returns the value of attribute recorder.
-
#redactor ⇒ Object
readonly
Returns the value of attribute redactor.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#watchdog ⇒ Object
readonly
Returns the value of attribute watchdog.
-
#watchdog_policy ⇒ Object
readonly
Returns the value of attribute watchdog_policy.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #closed? ⇒ Boolean
- #disabled? ⇒ Boolean
- #ensure_current_process! ⇒ Object
-
#initialize(settings:, watchdog_policy: nil, probes_enabled: false, clock: Clock.new, session_id_source: SecureRandom.method(:uuid), pid_source: Process.method(:pid), writer_factory: JSONL::Writer.method(:open), random: Sampler::RANDOM_SOURCE) ⇒ Lifecycle
constructor
A new instance of Lifecycle.
- #shutdown(exception: nil) ⇒ Object
Constructor Details
#initialize(settings:, watchdog_policy: nil, probes_enabled: false, clock: Clock.new, session_id_source: SecureRandom.method(:uuid), pid_source: Process.method(:pid), writer_factory: JSONL::Writer.method(:open), random: Sampler::RANDOM_SOURCE) ⇒ Lifecycle
Returns a new instance of Lifecycle.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 31 def initialize( settings:, watchdog_policy: nil, probes_enabled: false, clock: Clock.new, session_id_source: SecureRandom.method(:uuid), pid_source: Process.method(:pid), writer_factory: JSONL::Writer.method(:open), random: Sampler::RANDOM_SOURCE ) validate_dependencies!( settings, watchdog_policy, probes_enabled, clock, session_id_source, pid_source, writer_factory, random ) @settings = settings @watchdog_policy = watchdog_policy @probes_enabled = probes_enabled @clock = clock @session_id_source = session_id_source @pid_source = pid_source @writer_factory = writer_factory @random = random @owner_pid = current_pid @state = :starting @output_path = nil @recorder = nil @watchdog = nil @scheduler_observer = nil @active_operations = nil @redactor = nil @probe_registry = nil @execution_context_store = nil @rails_integration = nil start_process_session! rescue StandardError => e startup_failure!(e) end |
Instance Attribute Details
#active_operations ⇒ Object (readonly)
Returns the value of attribute active_operations.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def active_operations @active_operations end |
#execution_context_store ⇒ Object (readonly)
Returns the value of attribute execution_context_store.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def execution_context_store @execution_context_store end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def output_path @output_path end |
#owner_pid ⇒ Object (readonly)
Returns the value of attribute owner_pid.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def owner_pid @owner_pid end |
#probe_registry ⇒ Object (readonly)
Returns the value of attribute probe_registry.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def probe_registry @probe_registry end |
#rails_integration ⇒ Object (readonly)
Returns the value of attribute rails_integration.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def rails_integration @rails_integration end |
#recorder ⇒ Object (readonly)
Returns the value of attribute recorder.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def recorder @recorder end |
#redactor ⇒ Object (readonly)
Returns the value of attribute redactor.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def redactor @redactor end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def settings @settings end |
#watchdog ⇒ Object (readonly)
Returns the value of attribute watchdog.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def watchdog @watchdog end |
#watchdog_policy ⇒ Object (readonly)
Returns the value of attribute watchdog_policy.
22 23 24 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 22 def watchdog_policy @watchdog_policy end |
Class Method Details
.start ⇒ Object
27 28 29 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 27 def self.start(...) new(...) end |
Instance Method Details
#active? ⇒ Boolean
69 70 71 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 69 def active? @state == :active && recorder&.active? end |
#closed? ⇒ Boolean
77 78 79 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 77 def closed? @state == :closed end |
#disabled? ⇒ Boolean
73 74 75 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 73 def disabled? @state == :disabled || recorder&.disabled? end |
#ensure_current_process! ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 81 def ensure_current_process! pid = current_pid return self if pid == owner_pid abandon_inherited_runtime! @owner_pid = pid @output_path = nil @recorder = nil @watchdog = nil @scheduler_observer = nil @active_operations = nil @redactor = nil @probe_registry = nil @execution_context_store = nil @rails_integration = nil @state = :starting # Reset fiber-local context after fork ExecutionContext.reset! start_process_session! self rescue StandardError => e process_failure!(e) end |
#shutdown(exception: nil) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 105 def shutdown(exception: nil) ensure_current_process! return @summary if closed? runtime_error = stop_runtime_observers status = runtime_error && exception.nil? ? :degraded : shutdown_status(exception) @summary = recorder&.close(status: status) @state = :closed raise runtime_error if runtime_error && !settings.policy.fail_open? @summary rescue StandardError => e @state = :closed raise e unless settings.policy.fail_open? nil end |