Handle a RecordNotFound error when backfilling a repository

parent 8599ed03
module Geo module Geo
class RepositoryBackfillService class RepositoryBackfillService
attr_reader :project, :backfill_lease attr_reader :project_id, :backfill_lease
LEASE_TIMEOUT = 8.hours.freeze LEASE_TIMEOUT = 8.hours.freeze
LEASE_KEY_PREFIX = 'repository_backfill_service'.freeze LEASE_KEY_PREFIX = 'repository_backfill_service'.freeze
def initialize(project_id, backfill_lease) def initialize(project_id, backfill_lease)
@project = Project.find(project_id) @project_id = project_id
@backfill_lease = backfill_lease @backfill_lease = backfill_lease
end end
...@@ -21,10 +21,18 @@ module Geo ...@@ -21,10 +21,18 @@ module Geo
log('Finished repository sync') log('Finished repository sync')
end end
end end
rescue ActiveRecord::RecordNotFound
logger.error("Couldn't find project with ID=#{project_id}, skipping syncing")
ensure
Gitlab::ExclusiveLease.cancel(LEASE_KEY_PREFIX, backfill_lease)
end end
private private
def project
@project ||= Project.find(project_id)
end
def fetch_repositories def fetch_repositories
started_at = DateTime.now started_at = DateTime.now
finished_at = nil finished_at = nil
...@@ -67,7 +75,6 @@ module Geo ...@@ -67,7 +75,6 @@ module Geo
log('Releasing leases to sync repository') log('Releasing leases to sync repository')
Gitlab::ExclusiveLease.cancel(lease_key, repository_lease) Gitlab::ExclusiveLease.cancel(lease_key, repository_lease)
Gitlab::ExclusiveLease.cancel(LEASE_KEY_PREFIX, backfill_lease)
end end
def lease_key def lease_key
......
...@@ -12,6 +12,7 @@ class GeoBackfillWorker ...@@ -12,6 +12,7 @@ class GeoBackfillWorker
logger.info "Started Geo backfilling for #{project_ids.length} project(s)" logger.info "Started Geo backfilling for #{project_ids.length} project(s)"
project_ids.each do |project_id| project_ids.each do |project_id|
begin
break if Time.now - start >= RUN_TIME break if Time.now - start >= RUN_TIME
break unless node_enabled? break unless node_enabled?
...@@ -21,6 +22,10 @@ class GeoBackfillWorker ...@@ -21,6 +22,10 @@ class GeoBackfillWorker
try_obtain_lease do |lease| try_obtain_lease do |lease|
GeoSingleRepositoryBackfillWorker.new.perform(project_id, lease) GeoSingleRepositoryBackfillWorker.new.perform(project_id, lease)
end end
rescue ActiveRecord::RecordNotFound
logger.error("Couldn't find project with ID=#{project_id}, skipping syncing")
next
end
end end
logger.info "Finished Geo backfilling for #{project_ids.length} project(s)" logger.info "Finished Geo backfilling for #{project_ids.length} project(s)"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment