Sha256: 1b4a4dd891e1c279933b4971dfc7f1301c9cbb69ec8cc10e36f5da72c2f88b0e
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module FakeServiceBus module Actions class ReceiveMessage MAX_WAIT_TIME_SECONDS = 20 def initialize(options = {}) @server = options.fetch(:server) @queues = options.fetch(:queues) @start_ts = Time.now.to_f @satisfied = false end def call(queue_name, params) queue = @queues.get(queue_name) message = queue.receive_message(params.merge(queues: @queues)) @satisfied = !message.nil? || expired?(queue, params) if !message.nil? [201, {'location'=>message.location, 'BrokerProperties'=>{'SequenceNumber'=>message.sequence_number, 'LockToken'=>message.lock_token}.to_json}, message.body] end end def satisfied? @satisfied end protected def elapsed Time.now.to_f - @start_ts end def expired?(queue, params) wait_time_seconds = Integer params.fetch("timeout") { 0 } wait_time_seconds <= 0 || elapsed >= wait_time_seconds || elapsed >= MAX_WAIT_TIME_SECONDS end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fake_servicebus-0.0.2 | lib/fake_servicebus/actions/receive_message.rb |