延迟作业挂钩不起作用?
我试图让我的延迟工作挂钩发挥作用,但似乎没有。它们过时了吗?如果不是,您能给我举一个您的例子吗?
这是我的:
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
我说它们不起作用的原因是因为如果我上传一百张图像,其中一半会因错误而失败。如果引发错误,那么应该运行钩子,对吧?
问题是,如果我找到失败的照片,并运行 Photo.find(n).regenerate_styles!
,那么照片会正确重新生成并正常工作。
所以我猜测延迟作业的钩子不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们对我来说工作得很好:
我最初也遇到了类似的问题,由于过时的elasto_job gem(它实际上是作为插件安装的,这导致了我的问题),因此钩子没有被调用。不确定这些是否对您有帮助。
They've been working ok for me:
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.