简体   繁体   中英

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. 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). Here's the relevant code from my model file, 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:

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.

Any ideas?

EDIT: just another point; the same thing happens on heroku, not just locally.

Delayed job is capturing a stack trace for all failed jobs. It's saved in the last_error column of the delayed_jobs table. Use a database gui too see whats going on.

If you should be using Collective Ideas fork with ActiveRecord as backend you can query the model as usual. To fetch an array of all stack traces for example do

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

By default failed jobs are deleted after 25 failed attempts. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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