Stop Ruby on Rails from deleting multipage rack files created at boot time

When a file is uploaded to Rails, it creates a multi-line rack file in the / tmp folder.

RackMultipart20101109-31106-ylgoz0-0

After completing the request, I use delayed_job for the first process, then upload this tmp file to Amazon S3.

The problem starts when the rails (or racks) sporadically delete these files when a new download appears.

My server processes parallel file uploads ranging in size from 1 to 1000 MB, and quite often the file is deleted before it is uploaded to S3.

Is there a way to stop the rails (or rack) from deleting these files? Other solutions are also welcome.

+3
source share
1 answer

, fooobar.com/questions/1773746/... . :

, .

:

# In my controller:
Delayed::Job.enqueue(FileJob.new(params[:id], params[:upload].path))

# And In lib/file_job.rb
class FileJob < Struct.new(:file_id, :log_file) 
  def perform
    File.open(log_file)
    # Do important stuff with the incoming file.
  end
end

, delayed_job, , delayed_job ... Puff, , , , , .

:

# In my controller:
FileUtils.copy_entry(params[:upload].path, params[:upload].path + "B")
Delayed::Job.enqueue(FileJob.new(params[:id], params[:upload].path + "B"))

# And In lib/file_job.rb
class FileJob < Struct.new(:file_id, :log_file) 
  def perform
    File.open(log_file)
    # Do important stuff with the incoming file.
    FileUtils.remove(log_file)
  end
end

, . delayed_job, , , , .

, , . , , , .

+2

Source: https://habr.com/ru/post/1773744/


All Articles