Skip to content

Commit

Permalink
Add ability to configure vips_tmp_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
elohanlon committed Jan 9, 2025
1 parent 6eb067a commit 5718c8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 12 additions & 7 deletions config/initializers/derivativo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
FFMPEG.ffmpeg_binary = DERIVATIVO['ffmpeg_binary_path'] if DERIVATIVO['ffmpeg_binary_path'].present?
FFMPEG.ffprobe_binary = DERIVATIVO['ffprobe_binary_path'] if DERIVATIVO['ffprobe_binary_path'].present?

# If no working_directory is set, use default tmpdir.
# If working_directory is not set, default to ruby temp dir
if DERIVATIVO['working_directory'].blank?
DERIVATIVO['working_directory'] = Dir.tmpdir
else
# Create user-specified working directory if it doesn't already exist.
FileUtils.mkdir_p(DERIVATIVO['working_directory'])
DERIVATIVO['working_directory'] = File.join(Dir.tmpdir, Rails.application.class.module_parent_name.downcase)
end
# Make working if it does not already exist
FileUtils.mkdir_p(DERIVATIVO['working_directory'])

# Set the TMPDIR ENV variable so that Vips (via Imogen) writes temp files here.
# If vips_tmp_directory is not set, default to ruby temp dir
if DERIVATIVO['vips_tmp_directory'].blank?
DERIVATIVO['vips_tmp_directory'] = File.join(Dir.tmpdir, Rails.application.class.module_parent_name.downcase)
end
# Make vips_tmp_directory if it does not already exist
FileUtils.mkdir_p(DERIVATIVO['vips_tmp_directory'])
# Set the TMPDIR ENV variable so that Vips (via Imogen) writes temp files to the vips_tmp_directory.
# This defaults to the OS temp directory if not otherwise set, which can be a
# problem if we're on a host that has limited local disk space.
ENV['TMPDIR'] = DERIVATIVO['working_directory']
ENV['TMPDIR'] = DERIVATIVO['vips_tmp_directory']

Rails.application.config.active_job.queue_adapter = :inline if DERIVATIVO['run_queued_jobs_inline']
2 changes: 2 additions & 0 deletions config/templates/derivativo.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ development:
<<: *default
run_queued_jobs_inline: true
working_directory: <%= Rails.root.join('tmp', 'development', 'working_directory') %>
vips_tmp_directory: <%= Rails.root.join('tmp', 'development', 'working_directory') %>
remote_request_api_key: 'changethis'
tika_jar_path: '/path/to/tika-app.jar'
soffice_binary_path: '/path/to/soffice'
Expand All @@ -34,6 +35,7 @@ test:
<<: *default
run_queued_jobs_inline: true
working_directory: <%= Rails.root.join('tmp', 'test', 'working_directory') %>
vips_tmp_directory: <%= Rails.root.join('tmp', 'test', 'working_directory') %>
remote_request_api_key: 'changethis'
tika_jar_path: '/path/to/tika-app.jar'
soffice_binary_path: '/path/to/soffice'
Expand Down

0 comments on commit 5718c8c

Please sign in to comment.