Class: Stoplight::Domain::Strategies::GreenRunStrategy Private
- Inherits:
-
Object
- Object
- Stoplight::Domain::Strategies::GreenRunStrategy
- Includes:
- _RunStrategy
- Defined in:
- lib/stoplight/domain/strategies/green_run_strategy.rb,
sig/_private/stoplight/domain/strategies/green_run_strategy.rbs
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defines how the light executes when it is green.
This strategy clears failures after successful execution and handles errors by either raising them or invoking a fallback if provided.
Instance Attribute Summary collapse
- #request_tracker ⇒ Tracker::Request readonly private
Instance Method Summary collapse
-
#execute(fallback, state_snapshot:) { ... } ⇒ Object
private
Executes the provided code block when the light is in the green state.
-
#initialize(error_tracking_policy:, request_tracker:) ⇒ GreenRunStrategy
constructor
private
A new instance of GreenRunStrategy.
- #record_error(error) ⇒ void private
- #record_success ⇒ void private
Constructor Details
#initialize(error_tracking_policy:, request_tracker:) ⇒ GreenRunStrategy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of GreenRunStrategy.
13 14 15 16 |
# File 'lib/stoplight/domain/strategies/green_run_strategy.rb', line 13 def initialize(error_tracking_policy:, request_tracker:) @error_tracking_policy = error_tracking_policy @request_tracker = request_tracker end |
Instance Attribute Details
#request_tracker ⇒ Tracker::Request (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/stoplight/domain/strategies/green_run_strategy.rb', line 49 def request_tracker @request_tracker end |
Instance Method Details
#execute(fallback, state_snapshot:) { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes the provided code block when the light is in the green state.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stoplight/domain/strategies/green_run_strategy.rb', line 25 def execute(fallback, state_snapshot:, &code) # TODO: Consider implementing sampling rate to limit the memory footprint result = code.call record_success result rescue => error if @error_tracking_policy.track?(error) record_error(error) if fallback fallback.call(error) else raise end else # User chose to not track the error, so we record it as a success record_success raise end end |
#record_error(error) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
51 52 53 |
# File 'lib/stoplight/domain/strategies/green_run_strategy.rb', line 51 def record_error(error) request_tracker.record_failure(error) end |
#record_success ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
55 56 57 |
# File 'lib/stoplight/domain/strategies/green_run_strategy.rb', line 55 def record_success request_tracker.record_success end |