Hi Everyone, is it possible to share variables between the task and the state handlers. i want to send slack notifications based on my config parameter. the config is a dict which i want to use within the state handler post_to_slack function to send custom notifications.
k
Kevin Kho
11/02/2021, 4:32 PM
Not really, and I think this is because the state handler might need a bit of change in design. This should be easier in Orion but in the meantime, the only way is a hack of embedding it in context.
Copy code
@task
def abc():
prefect.context.my_var = here
or if it is returned, you can use the
state.result
.
inside your state handler, you can do
prefect.context.get("my_var")
. Not that mutating context doesn’t carry over succeeding tasks
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.