Commit a8600fc4 authored by Tiago Botelho's avatar Tiago Botelho

Adds logging to remove remote worker

parent c8e6c91c
......@@ -1005,22 +1005,22 @@ class Repository
add_remote(remote_name, url, mirror_refmap: refmap)
fetch_remote(remote_name, forced: forced)
ensure
schedule_remove_remote(remote_name) if tmp_remote_name
async_remove_remote(remote_name) if tmp_remote_name
end
def fetch_remote(remote, forced: false, ssh_auth: nil, no_tags: false)
gitlab_shell.fetch_remote(raw_repository, remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags)
end
def schedule_remove_remote(remote_name)
def async_remove_remote(remote_name)
return unless remote_name
job_id = RepositoryRemoveRemoteWorker.perform_async(project.id, remote_name)
if job_id
Rails.logger.info("RepositoryRemoveRemoteWorker job scheduled for #{project.id} with remote name: #{remote_name} job ID #{job_id}.")
Rails.logger.info("Remove remote job scheduled for #{project.id} with remote name: #{remote_name} job ID #{job_id}.")
else
Rails.logger.info("RepositoryRemoveRemoteWorker job failed to create for #{project.id} with remote name #{remote_name}.")
Rails.logger.info("Remove remote job failed to create for #{project.id} with remote name #{remote_name}.")
end
job_id
......
......@@ -8,10 +8,20 @@ class RepositoryRemoveRemoteWorker
def perform(project_id, remote_name)
@remote_name = remote_name
@project = Project.find(project_id)
@project = Project.find_by_id(project_id)
return unless @project
logger.info("Removing remote #{remote_name} from project #{project.id}")
try_obtain_lease do
@project.repository.remove_remote(remote_name)
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
......
......@@ -329,7 +329,7 @@ module EE
end
def remove_mirror_repository_reference
repository.schedule_remove_remote(::Repository::MIRROR_REMOTE)
repository.async_remove_remote(::Repository::MIRROR_REMOTE)
end
def import_url_availability
......
......@@ -72,12 +72,7 @@ class RemoteMirror < ActiveRecord::Base
end
def remote_name
name = read_attribute(:remote_name)
return name if name
return unless id
fallback_remote_name
super || fallback_remote_name
end
def update_failed?
......@@ -160,6 +155,8 @@ class RemoteMirror < ActiveRecord::Base
end
def fallback_remote_name
return unless id
"remote_mirror_#{id}"
end
......@@ -211,7 +208,7 @@ class RemoteMirror < ActiveRecord::Base
# the previous remote name
prev_remote_name = remote_name_was || fallback_remote_name
run_after_commit do
project.repository.schedule_remove_remote(prev_remote_name)
project.repository.async_remove_remote(prev_remote_name)
end
project.repository.add_remote(remote_name, url)
......@@ -220,7 +217,7 @@ class RemoteMirror < ActiveRecord::Base
def remove_remote
return unless project # could be pending to delete so don't need to touch the git repository
project.repository.schedule_remove_remote(remote_name)
project.repository.async_remove_remote(remote_name)
end
def mirror_url_changed?
......
......@@ -701,7 +701,7 @@ describe Repository do
end
end
describe '#schedule_remove_remote' do
describe '#async_remove_remote' do
before do
masterrev = repository.find_branch('master').dereferenced_target
create_remote_branch('joe', 'remote_branch', masterrev)
......@@ -716,7 +716,7 @@ describe Repository do
end
it 'returns job_id' do
expect(repository.schedule_remove_remote('joe')).to eq('1234')
expect(repository.async_remove_remote('joe')).to eq('1234')
end
end
......@@ -726,9 +726,9 @@ describe Repository do
end
it 'returns nil' do
expect(Rails.logger).to receive(:info).with("RepositoryRemoveRemoteWorker job failed to create for #{project.id} with remote name joe.")
expect(Rails.logger).to receive(:info).with("Remove remote job failed to create for #{project.id} with remote name joe.")
expect(repository.schedule_remove_remote('joe')).to be_nil
expect(repository.async_remove_remote('joe')).to be_nil
end
end
end
......
......@@ -25,7 +25,7 @@ describe RepositoryRemoveRemoteWorker do
context 'when project does not exist' do
it 'returns nil' do
expect { worker.perform(-1, 'remote_name') }.to raise_error(ActiveRecord::RecordNotFound)
expect(worker.perform(-1, 'remote_name')).to be_nil
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