class Soda::Retrier

Constants

MAX_TIMEOUT

AWS enforces a 12-hour maximum visibility timeout. If this is surpassed, the job is dead.

Public Instance Methods

retry(job_hash, msg) { || ... } click to toggle source
# File lib/soda/retrier.rb, line 9
def retry(job_hash, msg)
  yield
rescue => ex
  if postpone?(job_hash, msg)
    postpone(msg)
  end

  raise
end

Private Instance Methods

postpone(msg) click to toggle source
# File lib/soda/retrier.rb, line 31
def postpone(msg)
  sqs do |client|
    timeout =
      (Time.now - msg.first_received_at).to_i + (msg.receive_count ** 2)

    if timeout <= MAX_TIMEOUT
      client.change_message_visibility(
        queue_url:          msg.queue.lazy_url,
        receipt_handle:     msg.receipt,
        visibility_timeout: timeout,
      )
    else
      # This is not going to work; delete from the queue and move on. Bye
      # for good!
      msg.acknowledge
    end
  end
end
postpone?(job_hash, msg) click to toggle source
# File lib/soda/retrier.rb, line 21
def postpone?(job_hash, msg)
  ret = job_hash["retry"]

  if ret.is_a?(Numeric)
    ret < msg.receive_count
  else
    !!ret
  end
end