lib/sqs_buffer/client.rb in sqs_buffer-0.1.1 vs lib/sqs_buffer/client.rb in sqs_buffer-0.2.0
- old
+ new
@@ -49,22 +49,27 @@
def stop_polling
@running.make_false
end
- def queue_full?
+ def buffer_full?
@message_queue.length >= @max_queue_threshold.value
end
- def queue_empty?
+ def buffer_empty?
@message_queue.empty?
end
- def queue_length
+ def buffer_length
@message_queue.length
end
+ def buffer
+ # Return a copy of the array events to guard against potential mutation
+ Marshal.load( Marshal.dump(@message_queue) )
+ end
+
def shutting_down?
@running.false? && worker_thread_alive?
end
def running?
@@ -78,13 +83,10 @@
def last_process_time_stale?
@last_process_time.value < Time.now.to_i - @max_wait_time.value
end
def process_all_messages
- # This will be a collection of SQS messages
- # I am pretty sure this exposes the @message_queue to mutability
- # Maybe I should deep dup this?
- @process_block.value.call(@message_queue)
+ @process_block.value.call(buffer)
delete_all_messages
touch_process_time
rescue StandardError => e
@logger.error "An exception(#{e.message}) occurred while process the message queue: #{@message_queue.join("\n")} | Backtrace: #{e.backtrace}"
end