Commit e9e8a2f6 by Kamil Trzciński Committed by James Edwards-Jones

Asynchronously remove pages

parent 9ff381c4
......@@ -1186,7 +1186,11 @@ class Project < ActiveRecord::Base
end
def remove_pages
FileUtils.rm_r(pages_path, force: true)
temp_path = "#{path}.#{SecureRandom.hex}"
if Gitlab::PagesTransfer.new.rename_project(path, temp_path, namespace.path)
PagesWorker.perform_in(5.minutes, :remove, namespace.path, temp_path)
end
end
def wiki
......
......@@ -10,6 +10,6 @@ class UpdatePagesService
return unless data[:build_name] == 'pages'
return unless data[:build_status] == 'success'
PagesWorker.perform_async(data[:build_id])
PagesWorker.perform_async(:deploy, data[:build_id])
end
end
......@@ -7,7 +7,11 @@ class PagesWorker
sidekiq_options queue: :pages, retry: false
def perform(build_id)
def perform(action, *arg)
send(action, *arg)
end
def deploy(build_id)
@build_id = build_id
return unless valid?
......@@ -36,6 +40,11 @@ class PagesWorker
return false
end
def remove(namespace_path, project_path)
full_path = File.join(Settings.pages.path, namespace_path, project_path)
FileUtils.rm_r(full_path, force: true)
end
private
def create_status
......
......@@ -18,41 +18,48 @@ describe PagesWorker do
it 'succeeds' do
expect(project.pages_url).to be_nil
expect(worker.perform(build.id)).to be_truthy
expect(worker.deploy(build.id)).to be_truthy
expect(project.pages_url).to_not be_nil
end
it 'limits pages size' do
stub_application_setting(max_pages_size: 1)
expect(worker.perform(build.id)).to_not be_truthy
expect(worker.deploy(build.id)).to_not be_truthy
end
it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in)
expect(project.pages_url).to be_nil
expect(worker.perform(build.id)).to be_truthy
expect(worker.deploy(build.id)).to be_truthy
expect(project.pages_url).to_not be_nil
project.destroy
expect(Dir.exist?(project.public_pages_path)).to be_falsey
end
end
it 'fails to remove project pages when no pages is deployed' do
expect(PagesWorker).to_not receive(:perform_in)
expect(project.pages_url).to be_nil
project.destroy
end
it 'fails if no artifacts' do
expect(worker.perform(build.id)).to_not be_truthy
expect(worker.deploy(build.id)).to_not be_truthy
end
it 'fails for empty file fails' do
build.update_attributes(artifacts_file: empty_file)
expect(worker.perform(build.id)).to_not be_truthy
expect(worker.deploy(build.id)).to_not be_truthy
end
it 'fails for invalid archive' do
build.update_attributes(artifacts_file: invalid_file)
expect(worker.perform(build.id)).to_not be_truthy
expect(worker.deploy(build.id)).to_not be_truthy
end
it 'fails if sha on branch is not latest' do
commit.update_attributes(sha: 'old_sha')
build.update_attributes(artifacts_file: file)
expect(worker.perform(build.id)).to_not be_truthy
expect(worker.deploy(build.id)).to_not be_truthy
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