Is it possible to have `webhook_url` bound late at...
# flyte-v2-support
f
Is it possible to have
webhook_url
bound late at runtime only? union.ai/docs/…/run-with-notifications
Copy code
notify.Slack(
                on_phase=ActionPhase.SUCCEEDED,
                webhook_url=SLACK_WEBHOOK_URL,
                message="Run {{.Run.Name}} succeeded.",
            ),
The problem with current approach is that I have to know the webhook AT DEPLOYMENT time, which is problematic if I want to deploy the same job to two clusters. In v1, we had notification-on-failure that send out slack notification that just read the webhook url from mounted secrets at runtime. How to achieve the same in v2?
f
V1 did not have urls. You can send notifications on your own from driver task. Remember it's just code
f
In v1 we had
on_failure
that allowed late binding. From the "it's just code" - how to implement it properly then? I could try-except the main driver task but then it would fire notification on every restart, while I only want it to fire on specific phases (SUCCESS/FAILURE) of the main task (=whole "workflow")
f
It will not fire a notification on every restart
If you put it in a try except use a trace
f
I don't get it - so what's the point of the
notify.Slack
then if I have to code it differently anyway?
Something like this?
Copy code
@env.task
async def fail() -> int:
    raise ValueError("fail() always fails")


@env.task(retries=3)
async def main() -> int:
    try:
        return await fail()
    except flyte.errors.RuntimeUserError:
        if flyte.ctx().attempt_number >= main.retries.count:
            print("⚠️ SOMETHING WENT WRONG") # HERE SEND TO SLACK?
        raise
Feels odd, so my "what's the point of notify.Slack" still holds.
f
Hey @flat-waiter-82487. We haven't ship the notify feature into OSS v2 yet. If you need to do slack notification, you will need to implement it in your code.
f
Please update the docs then
f
cc @powerful-gold-59386 can you please help
p
👀
This fix is being merged now. An adjustment to flyte sdk docstring is also needed: @freezing-airport-6809 github.com/flyteorg/flyte-sdk/pull/1726