Commit e9e8a2f6 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Asynchronously remove pages

parent 9ff381c4
...@@ -1186,7 +1186,11 @@ class Project < ActiveRecord::Base ...@@ -1186,7 +1186,11 @@ class Project < ActiveRecord::Base
end end
def remove_pages 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 end
def wiki def wiki
......
...@@ -10,6 +10,6 @@ class UpdatePagesService ...@@ -10,6 +10,6 @@ class UpdatePagesService
return unless data[:build_name] == 'pages' return unless data[:build_name] == 'pages'
return unless data[:build_status] == 'success' return unless data[:build_status] == 'success'
PagesWorker.perform_async(data[:build_id]) PagesWorker.perform_async(:deploy, data[:build_id])
end end
end end
...@@ -7,7 +7,11 @@ class PagesWorker ...@@ -7,7 +7,11 @@ class PagesWorker
sidekiq_options queue: :pages, retry: false 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 @build_id = build_id
return unless valid? return unless valid?
...@@ -36,6 +40,11 @@ class PagesWorker ...@@ -36,6 +40,11 @@ class PagesWorker
return false return false
end 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 private
def create_status def create_status
......
...@@ -18,41 +18,48 @@ describe PagesWorker do ...@@ -18,41 +18,48 @@ describe PagesWorker do
it 'succeeds' do it 'succeeds' do
expect(project.pages_url).to be_nil 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 expect(project.pages_url).to_not be_nil
end end
it 'limits pages size' do it 'limits pages size' do
stub_application_setting(max_pages_size: 1) 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 end
it 'removes pages after destroy' do it 'removes pages after destroy' do
expect(PagesWorker).to receive(:perform_in)
expect(project.pages_url).to be_nil 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 expect(project.pages_url).to_not be_nil
project.destroy project.destroy
expect(Dir.exist?(project.public_pages_path)).to be_falsey expect(Dir.exist?(project.public_pages_path)).to be_falsey
end end
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 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 end
it 'fails for empty file fails' do it 'fails for empty file fails' do
build.update_attributes(artifacts_file: empty_file) 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 end
it 'fails for invalid archive' do it 'fails for invalid archive' do
build.update_attributes(artifacts_file: invalid_file) 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 end
it 'fails if sha on branch is not latest' do it 'fails if sha on branch is not latest' do
commit.update_attributes(sha: 'old_sha') commit.update_attributes(sha: 'old_sha')
build.update_attributes(artifacts_file: file) 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
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