Yanghui Ou
10/15/2020, 12:44 PMclass GenerateFile( Task ):
def run( self ):
with open( 'result.txt', 'w' ) as f:
f.write( f'This file is generated by {self.name}.' )
class ProcessFile( Task ):
def run( self ):
with open( 'result.txt', 'r' ) as f:
print( f.read() )
gen_task = GenerateFile()
print_task = PrintFile()
with Flow( 'test caching' ) as flow:
gen_result = gen_task()
print_result = print_task( upstream_tasks=[ gen_result ] )
Is there a better way to do it other than manually set the upstream_tasks
?
Another question is how can I specify the generated file as target such that I get the same caching behavior as make? I tried
gen_task = GenerateFile( target='result.txt', checkpoint=True, result=LocalResult( dir='.' ) )
but it does not seem to work.emre
10/15/2020, 1:19 PMGenerateFile
, and use the upstream value as filename in ProcessFile
, rather than hardcoding in ProcessFile
.
I am not experienced with make, or prefect checkpoints, but your caching may not be working because GenerateFile
has no return value, i.e. nothing to cache.Yanghui Ou
10/15/2020, 1:35 PMemre
10/16/2020, 6:43 AMProcessFile
handles how to read from local storage.