Closed Ramyani closed 5 years ago
did you ever get a resolution to this?
@Ramyani do you have multiple processes or threads doing conversions? If so, that is the issue. This gem uses the SAME tmp directory for all conversions and thus fails gloriously in that scenario.
def convert
Dir.mktmpdir do |target_path|
orig_stdout = $stdout.clone
$stdout.reopen File.new('/dev/null', 'w')
pid = Spoon.spawnp(@soffice_command, "--headless", "--convert-to", @convert_to, @source, "--outdir", target_path)
Process.waitpid(pid)
$stdout.reopen orig_stdout
target_tmp_file = "#{target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}"
FileUtils.cp target_tmp_file, @target
end
end
Doing this ensures each process has it's own temp directory AND that it gets cleaned up. (this bit us as well).
Another issue is the blind waitpid. We had a user upload a document to our conversion server that caused libreoffice to HANG for over 13hours!!
I ended up doing this.
pid = Spoon.spawnp(Commands.soffice, "--headless", "--convert-to", 'pdf', source, "--outdir", tmp_path)
if ! max_duration.nil?
start = Time.now
ret = nil
while ret.nil?
begin
ret = Process.waitpid(pid, Process::WNOHANG)
rescue => ex
raise IOError, 'Failed to convert document'
end
break unless ret.nil?
if (Time.now - start) > max_duration
# kill and reap the process
Process::kill('KILL', pid)
Process::waitpid(85415, Process::WNOHANG)
raise IOError, 'Document took too long to convert'
end
sleep 1
end
else
Process.waitpid(pid)
end
Dear @urkle, How can i replace your code to actual gem code? Please help me i am new to the Rails.
Hi sorry about this, this should be fixed in this commit: https://github.com/FormAPI/libreconv/commit/e41f747923f474df283d818db634655f85b1b956
But I just need to release a new version of the gem.
After upgrading the LibreOffice 4.2.8.2 420m0(Build:2) to LibreOffice 5.1.3.2 10m0(Build:2), I am suddenly getting error during docx conversion using the following command..
Libreconv.convert("test.html", "test.docx", ClockworkConfiguration.libreoffice.path, "docx")
I have the /tmp folder also have permission to write on it. Also I had closed all open instances of libreoffice.
How can I resolve this? And if it is the version of libreoffice that is causing this, what latest version should I use for this gem?