Class: Shoryuken::Polling::BaseStrategy Abstract
- Inherits:
-
Object
- Object
- Shoryuken::Polling::BaseStrategy
- Includes:
- Util
- Defined in:
- lib/shoryuken/polling/base_strategy.rb
Overview
Subclass and override #next_queue, #messages_found, and #active_queues to implement a custom polling strategy.
Abstract base class for queue polling strategies.
This class defines the interface that all polling strategies must implement to manage queue selection and message flow control in Shoryuken workers. Polling strategies determine which queue to fetch messages from next and how to handle scenarios where queues have no messages available.
Direct Known Subclasses
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this strategy with another object for equality.
-
#active_queues ⇒ Array
abstract
Returns the list of currently active queues.
-
#delay ⇒ Float
Returns the delay time for pausing empty queues.
-
#message_processed(_queue) ⇒ void
Called when a message from a queue has been processed.
-
#messages_found(_queue, _messages_found) ⇒ Object
abstract
Called when messages are found (or not found) in a queue.
-
#next_queue ⇒ QueueConfiguration?
abstract
Returns the next queue to poll for messages.
Methods included from Util
#elapsed, #fire_event, #logger, #unparse_queues, #worker_name
Instance Method Details
#==(other) ⇒ Boolean
Compares this strategy with another object for equality.
Two strategies are considered equal if they have the same active queues. This method also supports comparison with Array objects for backward compatibility.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 101 def ==(other) case other when Array @queues == other else if other.respond_to?(:active_queues) active_queues == other.active_queues else false end end end |
#active_queues ⇒ Array
Subclasses must implement this method
Returns the list of currently active queues.
This method should return an array representing the queues that are currently active and available for polling. The format may vary by strategy implementation.
89 90 91 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 89 def active_queues fail NotImplementedError end |
#delay ⇒ Float
Returns the delay time for pausing empty queues.
This method returns the amount of time (in seconds) that empty queues should be paused before being polled again. The delay can be set at the strategy level or falls back to the global Shoryuken delay setting.
121 122 123 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 121 def delay @delay || Shoryuken.[:delay].to_f end |
#message_processed(_queue) ⇒ void
This method returns an undefined value.
Called when a message from a queue has been processed.
This optional callback is invoked after a message has been successfully processed by a worker. Strategies can use this information for cleanup or to adjust their polling behavior.
78 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 78 def (_queue); end |
#messages_found(_queue, _messages_found) ⇒ Object
Subclasses must implement this method
Called when messages are found (or not found) in a queue.
This method is invoked after polling a queue to inform the strategy about the number of messages that were retrieved. Strategies can use this information to make decisions about future polling behavior, such as pausing empty queues or adjusting queue weights.
66 67 68 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 66 def (_queue, ) fail NotImplementedError end |
#next_queue ⇒ QueueConfiguration?
Subclasses must implement this method
Returns the next queue to poll for messages.
This method should return a QueueConfiguration object representing the next queue that should be polled for messages, or nil if no queues are currently available for polling.
51 52 53 |
# File 'lib/shoryuken/polling/base_strategy.rb', line 51 def next_queue fail NotImplementedError end |