https://prefect.io logo
Title
m

Michael Ludwig

07/29/2020, 6:39 PM
Does retrieving the tasks results locally still work as described in here? https://docs.prefect.io/core/idioms/task-results.html Wondering what I might do wrong (Only getting
None
):
end_state = flow.run(executor=executor,)
for result in end_state.result:
    <http://logger.info|logger.info>(f"Result: {result} -> {result.result}")
Flow run SUCCESS: all reference tasks succeeded
Result: <Task: user-to-cluster-snowflake-loader-free> -> None
Result: <Task: asp_ssm_parameter_writer> -> None
Result: <Task: mood_scorer> -> None
Result: <Task: rfy_predictor_FREE> -> None
Result: <Task: rfy_bucket_prefix_updater_Variants.main> -> None
Any ideas? Not using the newer
Result
construct though but would be great to grab the return values at the end of the flow run
j

josh

07/29/2020, 6:48 PM
Hi @Michael Ludwig the
end_state.result
is a dictionary so you need to iterate over the key value pair 🙂
for key, value in end_state.result.items():
    <http://logger.info|logger.info>(f"Result: {key} -> {value.result}")
For clarification: the key is a
Task
so your snippet is grabbing the result attribute of the task class (which is None) and the value is the state from the task run (which has a result)
m

Michael Ludwig

07/29/2020, 7:04 PM
Fantasic @josh. It worked. Stupid mistake on my side 😄 Thanks
@josh or any other person. Is it also possible to store other information in a task? I see the result is persisted but I also want to e.g. store some other info like the time it took to run a task. Stuff which I don’t return in the run function. I tried my luck with setting context and class attributes. But nothing really worked to be accessible after a flow run. Is it possible to store such info? Just talking about Prefect Core here.
j

josh

08/03/2020, 12:13 PM
@Michael Ludwig this is something that the use of Prefect core’s server or Prefect Cloud deal with by providing a backend persistence layer and API for recording such information. In order to do it purely in Core you would need to compute and store such information yourself (i.e. writing a timestamp at task start and then again at task end)