Class: SqsPoller::Process::TaskFinalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/sqspoller/process/task_finalizer.rb

Constant Summary collapse

DEFAULT_FINALIZE_TIMER_DELAY =
5.0
MAX_SQS_DELETE_BATCH_SIZE =
10
MAX_DELETE_RETRY =
5

Instance Method Summary collapse

Constructor Details

#initialize(buffer_size) ⇒ TaskFinalizer

Returns a new instance of TaskFinalizer.



21
22
23
24
25
26
# File 'lib/sqspoller/process/task_finalizer.rb', line 21

def initialize(buffer_size)
  @logger = SqsPoller::Logger.get_new_logger(self.class.name)
  @buffer_size = buffer_size
  @completed_tasks = SqsPoller::Common::RingBuffer.new(buffer_size * 2)
  schedule_timer
end

Instance Method Details

#buffer_sizeObject



28
29
30
# File 'lib/sqspoller/process/task_finalizer.rb', line 28

def buffer_size
  @buffer_size
end

#finalize(completed_task) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/sqspoller/process/task_finalizer.rb', line 32

def finalize(completed_task)
  @completed_tasks.push completed_task
  if @completed_tasks.count >= @buffer_size
    @timer.reset
    finalize_tasks
  end
end