如何处理嵌套作业的异常?

How to handle exceptions from nested jobs?

我有一个 Sidekiq / ActiveJob class 看起来像:

class ParentJob < ApplicationJob
  queue_as :default

  def perform(user)
    ChildJobA.perform_now(user)
    ChildJobB.perform_now(user)
    ChildJobC.perform_now(user)
    ...
  rescue CustomError => e
    handle_error(e)
  end
end

通过 ParentJob.perform_later(user) 调用父作业。

子作业可以养一个CustomError。我以为我可以拯救父工作中的那些人——但我的 rescue 块从未被调用过。似乎子作业只是退出并且控制权没有传回给父作业。

有没有办法挽救父作业中的自定义错误,或者我是否必须在每个子作业中重复相同的错误处理程序?

像普通 Ruby 代码一样调用它并从图片中删除 ActiveJob:

ChildJobA.new.perform(user)
ChildJobB.new.perform(user)
ChildJobC.new.perform(user)

这应该会正常提高。