Class: Stoplight::Domain::Strategies::RedRunStrategy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/domain/strategies/red_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 red.

This strategy prevents execution of the code block and either raises an error or invokes a fallback if provided.

Instance Method Summary collapse

Constructor Details

#initialize(name:, cool_off_time:) ⇒ RedRunStrategy

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 RedRunStrategy.



13
14
15
16
# File 'lib/stoplight/domain/strategies/red_run_strategy.rb', line 13

def initialize(name:, cool_off_time:)
  @name = name
  @cool_off_time = cool_off_time
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 fallback proc when the light is in the red state.

Parameters:

  • fallback

    A fallback proc to execute instead of the code block.

  • state_snapshot

Returns:

  • The result of the fallback proc if provided.

Raises:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stoplight/domain/strategies/red_run_strategy.rb', line 24

def execute(fallback, state_snapshot:)
  if fallback
    fallback.call(nil)
  else
    raise Error::RedLight.new(
      @name,
      cool_off_time: @cool_off_time,
      retry_after: state_snapshot.recovery_scheduled_after
    )
  end
end