Class: JayAPI::Abstract::WaitStrategy Abstract
- Inherits:
-
Object
- Object
- JayAPI::Abstract::WaitStrategy
- Defined in:
- lib/jay_api/abstract/wait_strategy.rb
Overview
This class is abstract.
Subclass and override #wait_time to implement a custom WaitStrategy.
Abstract base class for implementing different waiting strategies. This class provides a framework for implementing a strategy that dictates how long to wait before retrying an operation, typically used in situations where an operation might need to be retried multiple times (like network requests, etc.)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#wait_interval ⇒ Object
readonly
Returns the value of attribute wait_interval.
Instance Method Summary collapse
-
#initialize(wait_interval:, logger: nil) ⇒ WaitStrategy
constructor
A new instance of WaitStrategy.
-
#wait ⇒ Object
Executes the wait strategy.
Constructor Details
#initialize(wait_interval:, logger: nil) ⇒ WaitStrategy
Returns a new instance of WaitStrategy.
16 17 18 19 |
# File 'lib/jay_api/abstract/wait_strategy.rb', line 16 def initialize(wait_interval:, logger: nil) @wait_interval = wait_interval @logger = logger || Logging.logger($stdout) end |
Instance Attribute Details
#wait_interval ⇒ Object (readonly)
Returns the value of attribute wait_interval.
12 13 14 |
# File 'lib/jay_api/abstract/wait_strategy.rb', line 12 def wait_interval @wait_interval end |
Instance Method Details
#wait ⇒ Object
Executes the wait strategy. Logs the waiting time and pauses the execution for the determined wait time.
23 24 25 26 27 28 |
# File 'lib/jay_api/abstract/wait_strategy.rb', line 23 def wait wait_time.tap do |wait_time| logger.info("Sleeping: #{format('%.2f', wait_time)} s") Kernel.sleep(wait_time) end end |