Created
September 12, 2019 22:03
-
-
Save clarsen/57a3fab83136784f0e48db2f1a49b6cd to your computer and use it in GitHub Desktop.
Example forcible, replace-on-success Luigi task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() | |
# Example usage | |
class Generate(ForcibleTask): | |
date = luigi.DateParameter() | |
def output(self): | |
return luigi.LocalTarget( | |
self.date.strftime("generated-%Y-%m-%d") | |
) | |
# invocation | |
luigi --module generation Generate '--Generate-force-task-families=["Generate"]' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment