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
path: root/lib
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2018-11-20 17:46:22 +0300
committerToon Claes <toon@gitlab.com>2018-11-28 00:48:55 +0300
commit220208c051ef8a23c801662beeee6b60d00b4b18 (patch)
treeaca6765b47ac969f3f78c4fffa47393a724d7182 /lib
parentcc70bd8440d5de0c3e25dfa6e94337d4fbd245d3 (diff)
Retry the failing projects
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb61
1 files changed, 52 insertions, 9 deletions
diff --git a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
index ba62aee453c..a3b5324cc1d 100644
--- a/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
+++ b/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config.rb
@@ -12,7 +12,7 @@ module Gitlab
class HashedProject
attr_accessor :project
- ROOT_PATH_PREFIX = '@hashed'.freeze
+ ROOT_PATH_PREFIX = '@hashed'
def initialize(project)
@project = project
@@ -42,7 +42,7 @@ module Gitlab
end
# Concern used by Project and Namespace to determine the full
- # route the the project
+ # route to the project
module Routable
extend ActiveSupport::Concern
@@ -128,22 +128,65 @@ module Gitlab
end
end
- # Class to add the fullpath to the git repo config
- class Up
+ # Base class for Up and Down migration classes
+ class BackfillFullpathMigration
+ RETRY_DELAY = 15.minutes
+ MAX_RETRIES = 2
+
+ # Base class for retrying one project
+ class BaseRetryOne
+ def perform(project_id, retry_count)
+ project = Project.find(project_id)
+
+ migration_class.new.safe_perform_one(project, retry_count) if project
+ end
+ end
+
def perform(start_id, end_id)
Project.where(id: start_id..end_id).each do |project|
- project.add_fullpath_config
+ safe_perform_one(project)
end
end
+
+ def safe_perform_one(project, retry_count = 0)
+ perform_one(project)
+ rescue GRPC::NotFound, GRPC::InvalidArgument
+ nil
+ rescue GRPC::BadStatus
+ schedule_retry(project, retry_count + 1) if retry_count < MAX_RETRIES
+ end
+
+ def schedule_retry(project, retry_count)
+ BackgroundMigrationWorker.perform_in(RETRY_DELAY, self.class::RetryOne.name, [project.id, retry_count])
+ end
+ end
+
+ # Class to add the fullpath to the git repo config
+ class Up < BackfillFullpathMigration
+ # Class used to retry
+ class RetryOne < BaseRetryOne
+ def migration_class
+ Up
+ end
+ end
+
+ def perform_one(project)
+ project.add_fullpath_config
+ end
end
# Class to rollback adding the fullpath to the git repo config
- class Down
- def perform(start_id, end_id)
- Project.where(id: start_id..end_id).each do |project|
- project.remove_fullpath_config
+ class Down < BackfillFullpathMigration
+ # Class used to retry
+ class RetryOne < BaseRetryOne
+ def migration_class
+ Down
end
end
+
+ def perform_one(project)
+ project.remove_fullpath_config
+ end
end
end
end