Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/async_indexes/postgres_async_index.rb')
-rw-r--r--lib/gitlab/database/async_indexes/postgres_async_index.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/gitlab/database/async_indexes/postgres_async_index.rb b/lib/gitlab/database/async_indexes/postgres_async_index.rb
index dc932482d40..94ff4a69c62 100644
--- a/lib/gitlab/database/async_indexes/postgres_async_index.rb
+++ b/lib/gitlab/database/async_indexes/postgres_async_index.rb
@@ -8,17 +8,37 @@ module Gitlab
MAX_IDENTIFIER_LENGTH = Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH
MAX_DEFINITION_LENGTH = 2048
+ MAX_LAST_ERROR_LENGTH = 10_000
validates :name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
validates :table_name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
validates :definition, presence: true, length: { maximum: MAX_DEFINITION_LENGTH }
+ validates :last_error, length: { maximum: MAX_LAST_ERROR_LENGTH },
+ if: ->(index) { index.respond_to?(:last_error) }
scope :to_create, -> { where("definition ILIKE 'CREATE%'") }
scope :to_drop, -> { where("definition ILIKE 'DROP%'") }
+ scope :ordered, -> { order(attempts: :asc, id: :asc) }
def to_s
definition
end
+
+ def handle_exception!(error)
+ transaction do
+ increment!(:attempts)
+ update!(last_error: format_last_error(error))
+ end
+ end
+
+ private
+
+ def format_last_error(error)
+ [error.message]
+ .concat(error.backtrace)
+ .join("\n")
+ .truncate(MAX_LAST_ERROR_LENGTH)
+ end
end
end
end