Skip to content
Snippets Groups Projects
Commit eafb1fd5 authored by Stan Hu's avatar Stan Hu
Browse files

Ensure artifacts are moved locally within the filesystem to prevent timeouts

Closes #3068
parent 5a9b6b5e
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -110,10 +110,14 @@ def fog_public
end
def move_to_store
return true if object_store == LOCAL_STORE
file.try(:storage) == storage
end
def move_to_cache
return true if object_store == LOCAL_STORE
file.try(:storage) == cache_storage
end
......@@ -128,6 +132,13 @@ def exists?
file.try(:exists?)
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
def set_default_local_store(new_file)
......@@ -152,4 +163,14 @@ def remote_storage
def local_storage
CarrierWave::Storage::File.new(self)
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
......@@ -92,6 +92,11 @@
it "uploader is of a described_class" do
expect(uploader).to be_a(described_class)
end
it 'moves files locally' do
expect(uploader.move_to_store).to be(true)
expect(uploader.move_to_cache).to be(true)
end
end
context 'when store is null' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment