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

Remove locking and add force to FileUtils methods

parent 732a821d
...@@ -5,7 +5,7 @@ class PagesWorker ...@@ -5,7 +5,7 @@ class PagesWorker
BLOCK_SIZE = 32.kilobytes BLOCK_SIZE = 32.kilobytes
MAX_SIZE = 1.terabyte MAX_SIZE = 1.terabyte
sidekiq_options queue: :pages sidekiq_options queue: :pages, retry: false
def perform(build_id) def perform(build_id)
@build_id = build_id @build_id = build_id
...@@ -44,25 +44,17 @@ class PagesWorker ...@@ -44,25 +44,17 @@ class PagesWorker
FileUtils.mkdir_p(pages_path) FileUtils.mkdir_p(pages_path)
# Lock file for time of deployment to prevent the two processes from doing the concurrent deployment # Ignore deployment if the HEAD changed when we were extracting the archive
File.open(lock_path, File::RDWR|File::CREAT, 0644) do |f| return unless valid?
f.flock(File::LOCK_EX)
return unless valid? # Do atomic move of pages
# Move and removal may not be atomic, but they are significantly faster then extracting and removal
# Do atomic move of pages # 1. We move deployed public to previous public path (file removal is slow)
# Move and removal may not be atomic, but they are significantly faster then extracting and removal # 2. We move temporary public to be deployed public
# 1. We move deployed public to previous public path (file removal is slow) # 3. We remove previous public path
# 2. We move temporary public to be deployed public FileUtils.move(public_path, previous_public_path, force: true)
# 3. We remove previous public path FileUtils.move(temp_public_path, public_path)
if File.exists?(public_path) FileUtils.rm_r(previous_public_path, force: true)
FileUtils.move(public_path, previous_public_path)
end
FileUtils.move(temp_public_path, public_path)
end
if File.exists?(previous_public_path)
FileUtils.rm_r(previous_public_path, force: true)
end
@status.success @status.success
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