简体   繁体   English

delayed_job和paperclip - 图片未处理,但没有错误?

[英]delayed_job and paperclip - Images aren't processed, but no error?

I'm having big issues trying to get delayed_job working with Amazon S3 and Paperclip. 我试图让delayed_job使用Amazon S3和Paperclip时遇到大问题。 There are a few posts around about how to do it, but for whatever reason it's simply not working for me. 关于如何做到这一点有一些帖子,但无论出于何种原因,它根本不适合我。 I've removed a couple of things to how others are doing it - originally I had a save(validations => false) in regenerate_styles, but that seemed to cause an infinite loop (due to the after save catch), and didn't seem to be necessary (since the URLs have been saved, just the images not uploaded). 我已经删除了一些其他人正在做的事情 - 最初我在regenerate_styles中有一个保存(validations => false),但这似乎导致无限循环(由于后保存捕获),并且没有似乎是必要的(因为URL已被保存,只有未上传的图像)。 Here's the relevant code from my model file, submission.rb : 这是我的模型文件submission.rb中的相关代码:

class Submission < ActiveRecord::Base
  has_attached_file :photo ...

  ...

  before_photo_post_process do |submission|
    if photo_changed?
      false
    end
  end

  after_save do |submission|
    if submission.photo_changed?
      Delayed::Job.enqueue ImageJob.new(submission.id)
    end
  end

  def regenerate_styles!
    puts "Processing photo"
    self.photo.reprocess!
  end

  def photo_changed?
    self.photo_file_size_changed? ||
    self.photo_file_name_changed? ||
    self.photo_content_type_changed? ||
    self.photo_updated_at_changed?
  end
end

And my little ImageJob class that sites at the bottom of the submission.rb file: 而我的小ImageJob类位于submission.rb文件的底部:

class ImageJob < Struct.new(:submission_id)
  def perform
    Submission.find(self.submission_id).regenerate_styles!
  end
end

As far as I can tell, the job itself gets created correctly (as I'm able to pull it out of the database via a query). 据我所知,作业本身是正确创建的(因为我能够通过查询将其拉出数据库)。

The problem arises when: 问题出现在:

$ rake jobs:work
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
[Worker(host:Jarrod-Robins-MacBook.local pid:21738)] New Relic Ruby Agent Monitoring DJ worker host:MacBook.local pid:21738
[Worker(host:MacBook.local pid:21738)] Starting job worker
Processing photo
[Worker(host:MacBook.local pid:21738)] ImageJob completed after 9.5223
[Worker(host:MacBook.local pid:21738)] 1 jobs processed at 0.1045 j/s, 0 failed ...

The rake task then gets stuck and never exits, and the images themselves don't appear to have been reprocessed. 然后rake任务卡住并且永远不会退出,并且图像本身似乎没有被重新处理。

Any ideas? 有任何想法吗?

EDIT: just another point; 编辑:只是另一点; the same thing happens on heroku, not just locally. 同样的事情发生在heroku上,而不仅仅是本地。

Delayed job is capturing a stack trace for all failed jobs. 延迟作业正在捕获所有失败作业的堆栈跟踪。 It's saved in the last_error column of the delayed_jobs table. 它保存在delayed_jobs表的last_error列中。 Use a database gui too see whats going on. 使用数据库gui也看看发生了什么。

If you should be using Collective Ideas fork with ActiveRecord as backend you can query the model as usual. 如果你应该使用带有ActiveRecord的Collective Ideas fork作为后端,你可以照常查询模型。 To fetch an array of all stack traces for example do 要获取所有堆栈跟踪的数组,例如do

Delayed::Job.where('failed_at IS NOT NULL').map(&:last_error)

By default failed jobs are deleted after 25 failed attempts. 默认情况下,尝试失败25次后将删除失败的作业。 It may be that there are no jobs anymore. 可能不再有工作了。 Prevent deletion for debugging purposes by setting 通过设置防止删除以进行调试

Delayed::Worker.destroy_failed_jobs = false

in your config/initializers/delayed_job_config.rb 在你的config/initializers/delayed_job_config.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM