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

问题描述 投票:0回答:1

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

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块从未被调用过。似乎子作业只是退出而控制权不会传递回父作业。

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

sidekiq rails-activejob
1个回答
0
投票

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

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

应该正常显示。

© www.soinside.com 2019 - 2024. All rights reserved.