Commit 9567a1ee authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-fix-artifacts-moves' into 'master'

Ensure artifacts are moved locally within the filesystem to prevent timeouts

Closes #3068

See merge request !2572
parents 802079a4 54a2732c
...@@ -110,10 +110,14 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base ...@@ -110,10 +110,14 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
end end
def move_to_store def move_to_store
return true if object_store == LOCAL_STORE
file.try(:storage) == storage file.try(:storage) == storage
end end
def move_to_cache def move_to_cache
return true if object_store == LOCAL_STORE
file.try(:storage) == cache_storage file.try(:storage) == cache_storage
end end
...@@ -128,6 +132,13 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base ...@@ -128,6 +132,13 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
file.try(:exists?) file.try(:exists?)
end end
# Override this if you don't want to save local files by default to the Rails.root directory
def work_dir
# Default path set by CarrierWave:
# https://github.com/carrierwaveuploader/carrierwave/blob/v1.1.0/lib/carrierwave/uploader/cache.rb#L182
CarrierWave.tmp_path
end
private private
def set_default_local_store(new_file) def set_default_local_store(new_file)
...@@ -152,4 +163,14 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base ...@@ -152,4 +163,14 @@ class ObjectStoreUploader < CarrierWave::Uploader::Base
def local_storage def local_storage
CarrierWave::Storage::File.new(self) CarrierWave::Storage::File.new(self)
end end
# To prevent files in local storage from moving across filesystems, override
# the default implementation:
# http://github.com/carrierwaveuploader/carrierwave/blob/v1.1.0/lib/carrierwave/uploader/cache.rb#L181-L183
def workfile_path(for_file = original_filename)
# To be safe, keep this directory outside of the the cache directory
# because calling CarrierWave.clean_cache_files! will remove any files in
# the cache directory.
File.join(work_dir, @cache_id, version_name.to_s, for_file)
end
end end
---
title: Ensure artifacts are moved locally within the filesystem to prevent timeouts
merge_request: 2572
author:
...@@ -92,6 +92,11 @@ describe ObjectStoreUploader do ...@@ -92,6 +92,11 @@ describe ObjectStoreUploader do
it "uploader is of a described_class" do it "uploader is of a described_class" do
expect(uploader).to be_a(described_class) expect(uploader).to be_a(described_class)
end end
it 'moves files locally' do
expect(uploader.move_to_store).to be(true)
expect(uploader.move_to_cache).to be(true)
end
end end
context 'when store is null' do context 'when store is null' do
......
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