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.
-
#operation_liveness_monitor ⇒ Object
readonly
Returns the value of attribute operation_liveness_monitor.
-
#operation_liveness_policy ⇒ Object
readonly
Returns the value of attribute operation_liveness_policy.
-
#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, operation_liveness_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, operation_liveness_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.
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 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 34 def initialize( settings:, watchdog_policy: nil, operation_liveness_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, operation_liveness_policy, probes_enabled, clock, session_id_source, pid_source, writer_factory, random ) @settings = settings @watchdog_policy = watchdog_policy @operation_liveness_policy = operation_liveness_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 reset_process_components! start_process_session! rescue StandardError => e startup_failure!(e) end |
Instance Attribute Details
#active_operations ⇒ Object (readonly)
Returns the value of attribute active_operations.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def active_operations @active_operations end |
#execution_context_store ⇒ Object (readonly)
Returns the value of attribute execution_context_store.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def execution_context_store @execution_context_store end |
#operation_liveness_monitor ⇒ Object (readonly)
Returns the value of attribute operation_liveness_monitor.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def operation_liveness_monitor @operation_liveness_monitor end |
#operation_liveness_policy ⇒ Object (readonly)
Returns the value of attribute operation_liveness_policy.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def operation_liveness_policy @operation_liveness_policy end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def output_path @output_path end |
#owner_pid ⇒ Object (readonly)
Returns the value of attribute owner_pid.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def owner_pid @owner_pid end |
#probe_registry ⇒ Object (readonly)
Returns the value of attribute probe_registry.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def probe_registry @probe_registry end |
#rails_integration ⇒ Object (readonly)
Returns the value of attribute rails_integration.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def rails_integration @rails_integration end |
#recorder ⇒ Object (readonly)
Returns the value of attribute recorder.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def recorder @recorder end |
#redactor ⇒ Object (readonly)
Returns the value of attribute redactor.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def redactor @redactor end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def settings @settings end |
#watchdog ⇒ Object (readonly)
Returns the value of attribute watchdog.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def watchdog @watchdog end |
#watchdog_policy ⇒ Object (readonly)
Returns the value of attribute watchdog_policy.
24 25 26 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 24 def watchdog_policy @watchdog_policy end |
Class Method Details
.start ⇒ Object
30 31 32 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 30 def self.start(...) new(...) end |
Instance Method Details
#active? ⇒ Boolean
66 67 68 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 66 def active? @state == :active && recorder&.active? end |
#closed? ⇒ Boolean
74 75 76 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 74 def closed? @state == :closed end |
#disabled? ⇒ Boolean
70 71 72 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 70 def disabled? @state == :disabled || recorder&.disabled? end |
#ensure_current_process! ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 78 def ensure_current_process! pid = current_pid return self if pid == owner_pid abandon_inherited_runtime! @owner_pid = pid reset_process_components! @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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fiber_audit/runtime/lifecycle.rb', line 94 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 |