开发者

Delayed Jobs Hooks do not work?

开发者 https://www.devze.com 2023-02-16 02:18 出处:网络
I\'m trying to make my delayed jobs hooks work, but they don\'t seem to be. Are they outdated? If they are not, can you show me an example of yours?

I'm trying to make my delayed jobs hooks work, but they don't seem to be. Are they outdated? If they are not, can you show me an example of yours?

Here's mine:

class PhotoJob < Struct.new(:image_id)
  def perform
    Photo.find(self.image_id).regenerate_styles!
  end
  def error(job, exception)
    if Photo.exists?(self.image_id)
      Photo.find(self.image_id).regenerate_styles!
    else
      Delayed::Job.find(self).destroy
    end
  end
end

The reason I say they do not work is because if I upload a hundred images, half of them will fail with an error. If the开发者_开发技巧 error is raised, then the hook should be run, right?

Here's the catch, if I find the photo that's failing, and run Photo.find(n).regenerate_styles! , then the photo regenerates appropriately and works.

So I'm guessing that Delayed Jobs' hooks are not working.


They've been working ok for me:

class BaseProcessorJob
  def perform
    raise NotImplementedError
  end

  def error(job, exception)
    Rails.logger.error "Job failed #{exception}"
  end
end

I originally had a similar problem with hooks not getting called because of an outdated delayed_job gem (it was actually installed as a plugin, which caused my problems). Not sure if any of that helps you though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号