Class: Stoplight::Domain::Strategies::GreenRunStrategy Private
- Inherits:
-
Object
- Object
- Stoplight::Domain::Strategies::GreenRunStrategy
- Defined in:
- lib/stoplight/domain/strategies/green_run_strategy.rb
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 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.
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 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 |