Thread
#prefect-community
    Marko Herkaliuk

    Marko Herkaliuk

    10 months ago
    hi, maybe I’m tired today, but I can’t figure out if I can set / change the context variable inside of the Flow block.
    why do i need this. I have state_handler for notification in slack when flow is failed. and i want have sm like this
    msg = (
                f"Hey <@{prefect.context.flow_owner}>\n"
                f"Run `{prefect.context.flow_run_name}` of flow `{prefect.context.flow_name}` "
                f"entered `FAILED` state with message `{state.message}`."
                f"See {prefect.context.flow_run_link} for more details."
            )
    for personal notification. And I want move this handler in our lib and don’t write this handler in every file
    Kevin Kho

    Kevin Kho

    10 months ago
    Hey @Marko Herkaliuk, the context is not really meant to be mutated like this. I think it will work sometimes, but I don’t think you can do this in the Flow block. It has to be in a task because the Flow block is not deferred, while tasks are.
    Anna Geller

    Anna Geller

    10 months ago
    this documentation page explains it nicely: you can modify the context, but ideally you shouldn’t have to do it 🙂 https://docs.prefect.io/core/concepts/execution.html#prefect-supplied-context
    @Marko Herkaliuk the state handler can be defined in some custom module, and the context values will still be filled based on runtime values - so you can move it to your custom library
    last point: flow_run_link could be constructed this way:
    f"<https://cloud.prefect.io/{your_tenant}/flow-run/{flow_run_id}>"
    Marko Herkaliuk

    Marko Herkaliuk

    10 months ago
    I just setup env variable with owner for personal notification ) thnx @Kevin Kho @Anna Geller