简体   繁体   English

延迟工作挂钩不起作用?

[英]Delayed Jobs Hooks do not work?

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! 如果发现失败的照片,然后运行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). 最初,我有一个类似的问题,因为过时的delay_job gem(实际上是作为插件安装的,这导致了我的问题),挂钩没有被调用。 Not sure if any of that helps you though. 不确定是否有任何帮助。

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

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