Ben
08/28/2024, 9:39 PM@flow(name="hello-flow")
def hello_world():
future = say_hello.submit("Marvin")
# in this case the task would return {"key": "Marvin"} instead of the original.
print_result.submit(future.result()["key"])
Nate
08/28/2024, 10:20 PMIs the code below the best way to only pass a portion of a result to the next task?is that you can't, you'd have to resolve the whole future and pass whatever portion of it on you care about but I'd be curious why you want to do that, ie why doesn't your
say_hello
task just return
the part that you want to pass to the next task? perhaps there's a more convenient way to design your taskNate
08/28/2024, 10:22 PM.submit
or .result()
and you could just do
@flow(name="hello-flow")
def hello_world():
result = say_hello("Marvin")
# in this case the task would return {"key": "Marvin"} instead of the original.
print_result(result["key"])
Ben
08/28/2024, 10:28 PM{'result1': link_to_side_effect_file1, 'result2' link_to_side_effect_file2}
But then that result feeds into 2 different tasks one of which uses result1, the other result2.
I'm not completely certain I've got the best design. I've used luigi heavily in the past so there is the temptation to try to make Prefect look like luigi.Ben
08/28/2024, 10:34 PM@task
def task1():
return {'result1': 'thing for task2',
'result2': 'thing for task3'}
@task
def task2(input_value):
return f'task2: {input_value}'
@task
def task3(input_value):
return f'task3: {input_value}'
@flow
async def test():
task1_result = task1()
task2_result = task2(task1_result['result1'])
task3_result = task3(task1_result['result2'])
print([task1_result, task2_result, task3_result])
Nate
08/28/2024, 10:35 PMBen
08/28/2024, 10:39 PMNate
08/28/2024, 10:39 PM@flow
def test():
task1_result = task1()
task2_future = task2.submit(task1_result["result1"])
task3_future = task3.submit(task1_result["result2"])
print([task1_result, task2_future.result(), task3_future.result()])
Nate
08/28/2024, 10:44 PM.submit
or .map
calls inside if
/ else
branches etc because we build the graph as your code runs, ie you only get a node in your "DAG" once you call / submit the taskBen
08/28/2024, 10:48 PMNate
08/28/2024, 10:53 PM