我使用它来强制重新生成输出而无需先将其删除,并允许您选择要重新生成的类型。在我们的用例中,我们希望旧生成的文件继续存在,直到它们被新版本重写。
# generation.py
class ForcibleTask(luigi.Task):
force_task_families = luigi.ListParameter(
positional=False, significant=False, default=[]
)
def complete(self):
print("{}: check {}".format(self.get_task_family(), self.output().path))
if not self.output().exists():
self.oldinode = 0 # so any new file is considered complete
return False
curino = pathlib.Path(self.output().path).stat().st_ino
try:
x = self.oldinode
except AttributeError:
self.oldinode = curino
if self.get_task_family() in self.force_task_families:
# only done when file has been overwritten with new file
return self.oldinode != curino
return self.output().exists()
示例用法
class Generate(ForcibleTask):
date = luigi.DateParameter()
def output(self):
return luigi.LocalTarget(
self.date.strftime("generated-%Y-%m-%d")
)
调用
luigi --module generation Generate '--Generate-force-task-families=["Generate"]'