lib/fluent/plugin/bigquery/errors.rb in fluent-plugin-bigquery-3.2.0 vs lib/fluent/plugin/bigquery/errors.rb in fluent-plugin-bigquery-3.3.0

- old
+ new

@@ -3,10 +3,11 @@ # @abstract class Error < StandardError RETRYABLE_ERROR_REASON = %w(backendError internalError rateLimitExceeded tableUnavailable).freeze RETRYABLE_INSERT_ERRORS_REASON = %w(timeout backendError internalError rateLimitExceeded).freeze RETRYABLE_STATUS_CODE = [500, 502, 503, 504] + REGION_NOT_WRITABLE_MESSAGE = -"is not writable in the region" class << self # @param e [Google::Apis::Error] # @param message [String] def wrap(e, message = nil) @@ -17,18 +18,26 @@ end end # @param e [Google::Apis::Error] def retryable_error?(e) + retryable_server_error?(e) || retryable_region_not_writable?(e) + end + + def retryable_server_error?(e) e.is_a?(Google::Apis::ServerError) && RETRYABLE_STATUS_CODE.include?(e.status_code) end def retryable_error_reason?(reason) RETRYABLE_ERROR_REASON.include?(reason) end def retryable_insert_errors_reason?(reason) RETRYABLE_INSERT_ERRORS_REASON.include?(reason) + end + + def retryable_region_not_writable?(e) + e.is_a?(Google::Apis::ClientError) && e.status_code == 400 && e.message.include?(REGION_NOT_WRITABLE_MESSAGE) end # Guard for instantiation private :new def inherited(subclass)