Class: Proletariat::Subscriber::Acknowledger
- Inherits:
-
Object
- Object
- Proletariat::Subscriber::Acknowledger
- Includes:
- Concerns::Logging
- Defined in:
- lib/proletariat/subscriber.rb
Overview
Internal: Used to watch the state of dispatched Work and send ack/nack
to a RabbitMQ channel.
Constant Summary collapse
- MAX_BLOCK_TIME =
Public: Maximum time in seconds to wait synchronously for an
acknowledgement.
5
Instance Method Summary collapse
-
#acknowledge_on_channel(channel) ⇒ Object
Public: Retrieves the value from the ivar and sends the relevant acknowledgement on a given channel.
-
#block_until_acknowledged(channel) ⇒ Object
Public: Blocks until acknowledgement completes.
-
#initialize(ivar, delivery_tag, message, exception_handler) ⇒ Acknowledger
constructor
Public: Creates a new Acknowledger instance.
-
#ready_to_acknowledge? ⇒ Boolean
Public: Gets the readiness of the ivar for acknowledgement use.
Methods included from Concerns::Logging
Constructor Details
#initialize(ivar, delivery_tag, message, exception_handler) ⇒ Acknowledger
Public: Creates a new Acknowledger instance.
ivar - A ivar-like object holding the Worker response. delivery_tag - The RabbitMQ delivery tag for ack/nacking. message - The original message; for exception handling. exception_handler - A reference to an ExceptionHandler.
197 198 199 200 201 202 |
# File 'lib/proletariat/subscriber.rb', line 197 def initialize(ivar, delivery_tag, , exception_handler) @ivar = ivar @delivery_tag = delivery_tag @message = @exception_handler = exception_handler end |
Instance Method Details
#acknowledge_on_channel(channel) ⇒ Object
Public: Retrieves the value from the ivar and sends the relevant
acknowledgement on a given channel. Logs a warning if the
ivar value is unexpected.
channel - The Bunny::Channel to receive the acknowledgement.
Returns nil.
211 212 213 214 215 216 217 218 219 |
# File 'lib/proletariat/subscriber.rb', line 211 def acknowledge_on_channel(channel) if ivar.fulfilled? acknowledge_success(channel) elsif ivar.rejected? acknowledge_error(channel) end nil end |
#block_until_acknowledged(channel) ⇒ Object
Public: Blocks until acknowledgement completes.
channel - The Bunny::Channel to receive the acknowledgement.
Returns nil.
226 227 228 229 230 231 |
# File 'lib/proletariat/subscriber.rb', line 226 def block_until_acknowledged(channel) ivar.wait(MAX_BLOCK_TIME) acknowledge_on_channel(channel) nil end |
#ready_to_acknowledge? ⇒ Boolean
Public: Gets the readiness of the ivar for acknowledgement use.
Returns true if ivar is fulfilled or rejected.
236 237 238 |
# File 'lib/proletariat/subscriber.rb', line 236 def ready_to_acknowledge? ivar.completed? end |