2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
class RepositoryRemoveRemoteWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-05-03 12:55:14 +00:00
|
|
|
include ApplicationWorker
|
|
|
|
include ExclusiveLeaseGuard
|
|
|
|
|
2019-10-18 11:11:44 +00:00
|
|
|
feature_category :source_code_management
|
|
|
|
|
2018-05-03 12:55:14 +00:00
|
|
|
LEASE_TIMEOUT = 1.hour
|
|
|
|
|
|
|
|
attr_reader :project, :remote_name
|
|
|
|
|
|
|
|
def perform(project_id, remote_name)
|
|
|
|
@remote_name = remote_name
|
|
|
|
@project = Project.find_by_id(project_id)
|
|
|
|
|
|
|
|
return unless @project
|
|
|
|
|
|
|
|
logger.info("Removing remote #{remote_name} from project #{project.id}")
|
|
|
|
|
|
|
|
try_obtain_lease do
|
|
|
|
remove_remote = @project.repository.remove_remote(remote_name)
|
|
|
|
|
|
|
|
if remove_remote
|
|
|
|
logger.info("Remote #{remote_name} was successfully removed from project #{project.id}")
|
|
|
|
else
|
|
|
|
logger.error("Could not remove remote #{remote_name} from project #{project.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def lease_timeout
|
|
|
|
LEASE_TIMEOUT
|
|
|
|
end
|
|
|
|
|
|
|
|
def lease_key
|
|
|
|
"remove_remote_#{project.id}_#{remote_name}"
|
|
|
|
end
|
|
|
|
end
|