【发布时间】:2018-02-23 20:49:47
【问题描述】:
是否有推荐的惯例来支持或反对为不同的工作使用相同的工作类别?我试图避免为从父级生成的子作业创建单独的作业类。
我意识到 Sidekiq::Batch 可以处理来自父级的跟踪派生作业,但它不能解决对不同作业使用同一个类的问题。
例如:
# not ideal: requires separate child job class
class ParentJob < ApplicationJob
def perform(*args)
MyModel.all.each { |f| ChildJob.perform_later(f) }
end
end
# ideal - allows re-use of same class
class ParentJob < ApplicationJob
def perform(*args)
# doesn't work, but shown here conceptually
MyModel.all.each { |f| self.class.perform(:foo, f) }
end
def foo(f); end
end
我可以查看父作业的参数,如果它包含一个特殊的键,分支并运行不同的方法,但我不喜欢这种方法的模棱两可的合同。
【问题讨论】: