【发布时间】:2017-10-06 19:12:30
【问题描述】:
我最近实施了一个 luigi 管道来处理我们的一个生物信息学管道的处理。但是,关于如何设置这些任务的一些基本知识我没有掌握。
假设我有一个包含三个任务的链,我希望能够与多个工作人员一起运行。例如,三个工作人员的依赖关系图可能如下所示:
/taskC -> taskB -> taskA
- 任务C -> 任务B -> 任务A
\ taskC -> taskB -> taskA
我可能会写
class entry(luigi.Task):
in_dir = luigi.Parameter()
def requires(self):
for f in self.in_dir:
yield taskC(pass_through=f)
def run(self):
some logic using self.input().path
from each worker in the above yield
class taskA(luigi.Task):
in_file_A = luigi.Parameter()
def output(self):
return luigi.LocalTarget('outA.txt')
def run(self):
some logic generating outA.txt
class taskB(luigi.Task):
pass_through = luigi.Parameter()
def output(self):
return luigi.LocalTarget('outB.txt')
def requires(self):
return taskA(in_file_A=self.pass_through)
def run(self):
some logic using self.input().path [outA.txt]
and generating self.output().path [outB.txt]
class taskC(luigi.Task):
pass_through = luigi.Parameter()
def output(self):
return luigi.LocalTarget('outC.txt')
def requires(self):
return taskB(pass_through=self.pass_through)
def run(self):
some logic using self.input().path [outB.txt]
and generating self.output().path [outC.txt]
如果我的代码位于 pipeline.py,我可能会使用以下命令启动它:
luigi --module pipeline entry --workers 3 --in-dir some_dir_w_input_files/
我将参数pass_through 一直发送到taskA 的事实感觉不是正确的方法。此外,如果将来某个时候我已经拥有taskA(单独)生成的数据,taskB 不够灵活,无法处理这种情况。也许我可以写:
class taskB(luigi.Task):
in_file_B = luigi.Parameter() # if we already have the output of taskA
pass_through = luigi.Parameter() # if we require taskA
def output(self):
return luigi.LocalTarget('outB.txt')
def requires(self):
if self.pass_through:
return taskA(in_file_A=self.pass_through)
def run(self):
if self.input().path:
logic_input = self.input().path
else:
logic_input = self.in_file_B
some logic using 'logic_input'
and generating self.output().path [outB.txt]
我想知道这是否是 Luigi 的“正确”设计模式,或者我是否完全偏离了基础。
【问题讨论】: