Currently, I have a bunch of luigi tasks queued together, with a simple dependency chain( a -> b -> c -> d
). d
gets executed first, and
I typically do this by overriding complete()
:
class BaseTask(luigi.Task):
force = luigi.BoolParameter()
def complete(self):
outputs = luigi.task.flatten(self.output())
for output in outputs:
if self.force and output.exists():
output.remove()
return all(map(lambda output: output.exists(), outputs))
class MyTask(BaseTask):
def output(self):
return luigi.LocalTarget("path/to/done/file.txt")
def run(self):
with self.output().open('w') as out_file:
out_file.write('Complete')
When you run the task, the output file is created as expected. Upon instantiating the class with force=True
, the output file will still exist until complete()
is called.
task = MyTask()
task.run()
task.complete()
# True
new_task = MyTask(force=True)
new_task.output().exists()
# True
new_task.complete()
# False
new_task.output().exists()
# False