class Google::Cloud::Bigquery::Service::Backoff
def execute
def execute current_retries = 0 loop do return yield rescue Google::Apis::Error => e raise e unless retry? e.body, current_retries @backoff.call current_retries current_retries += 1 end end
def initialize retries: nil, reasons: nil, backoff: nil
def initialize retries: nil, reasons: nil, backoff: nil @retries = (retries || Backoff.retries).to_i @reasons = (reasons || Backoff.reasons).to_a @backoff = backoff || Backoff.backoff end
def retry? result, current_retries
def retry? result, current_retries if current_retries < @retries && retry_error_reason?(result) return true end false end
def retry_error_reason? err_body
def retry_error_reason? err_body err_hash = JSON.parse err_body json_errors = Array err_hash["error"]["errors"] return false if json_errors.empty? json_errors.each do |json_error| return false unless @reasons.include? json_error["reason"] end true rescue StandardError false end