【发布时间】:2016-06-15 16:23:18
【问题描述】:
我有一个带有回形针附件(图像或 pdf 文件)的模型。我正在使用 Sidekiq 在后台进程中处理此模型。在后台过程中,我使用 imagemagick convert 函数将 pdf 文件转换为 pdf 文件字符串,以消除文件格式中的任何密码保护或垃圾。
此转换在我的开发环境的 sidekiq 和暂存服务器的 sidekiq 上运行良好,但在生产服务器的 sidekiq 上不起作用。在我的生产服务器上,如果我从 Rails 控制台运行转换方法,它就可以工作。当它不工作时,dst 文件为空,返回的字符串为''
模型是这样的
class Receipt < ActiveRecord::Base
has_attached_file :image, styles: { original: {} }, path: ':rails_root/attachments/:class/:attachment/:id_partition/:style/:filename'
validates_attachment_content_type :image, :content_type => IMAGE_MIME_TYPES
def convert_pdf_to_pdf_string
if %w(application/pdf application/octet-stream).include?(image.content_type)
begin
dst = Tempfile.new([File.basename(image.path, File.extname(image.path)), '.pdf'], :encoding => 'ascii-8bit')
dst.flush
`convert -density 200 #{image.path.shellescape} #{dst.path.shellescape}`
dst
str = File.open(dst.path, 'rb') {|f| f.read}.to_s
ensure
dst.close
dst.unlink
end
end
end
end
我不知道如何调试这个问题。
没有引发异常。我还尝试记录反引号调用的返回值,但没有返回任何内容。
请提出我应该检查的任何想法。
【问题讨论】:
-
你在使用 Heroku 吗(生产服务器)?
-
不,它是 Debian 服务器。暂存服务器和生产服务器的配置方式应相同。
-
使用 pry-remote 之类的东西,设置断点,然后检查发生了什么。
标签: ruby-on-rails imagemagick sidekiq