Handle a RecordNotFound error when backfilling a repository

parent 8599ed03
module Geo
class RepositoryBackfillService
attr_reader :project, :backfill_lease
attr_reader :project_id, :backfill_lease
LEASE_TIMEOUT = 8.hours.freeze
LEASE_KEY_PREFIX = 'repository_backfill_service'.freeze
def initialize(project_id, backfill_lease)
@project = Project.find(project_id)
@project_id = project_id
@backfill_lease = backfill_lease
end
......@@ -21,10 +21,18 @@ module Geo
log('Finished repository sync')
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
private
def project
@project ||= Project.find(project_id)
end
def fetch_repositories
started_at = DateTime.now
finished_at = nil
......@@ -67,7 +75,6 @@ module Geo
log('Releasing leases to sync repository')
Gitlab::ExclusiveLease.cancel(lease_key, repository_lease)
Gitlab::ExclusiveLease.cancel(LEASE_KEY_PREFIX, backfill_lease)
end
def lease_key
......
......@@ -12,14 +12,19 @@ class GeoBackfillWorker
logger.info "Started Geo backfilling for #{project_ids.length} project(s)"
project_ids.each do |project_id|
break if Time.now - start >= RUN_TIME
break unless node_enabled?
project = Project.find(project_id)
next if project.repository_exists?
try_obtain_lease do |lease|
GeoSingleRepositoryBackfillWorker.new.perform(project_id, lease)
begin
break if Time.now - start >= RUN_TIME
break unless node_enabled?
project = Project.find(project_id)
next if project.repository_exists?
try_obtain_lease do |lease|
GeoSingleRepositoryBackfillWorker.new.perform(project_id, lease)
end
rescue ActiveRecord::RecordNotFound
logger.error("Couldn't find project with ID=#{project_id}, skipping syncing")
next
end
end
......
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