I have many tasks distributed across files, and one slack_notifier handler that they all import and utilize. What is a good pattern for disabling/using a different handler for local dev. I cannot run flows locally unless i change the handler because i get a
ValueError: Local Secret "SLACK_WEBHOOK_URL" was not found.
Jacob Goldberg
10/22/2021, 6:55 PM
I tried this pattern, but it doesnt seem to work because the secrets are not actually checked until flows are run, so there is no exception defining the initial handler:
I also tried this pattern, but it did not seem to work either:
Copy code
if Secret("SLACK_WEBHOOK_URL").exists():
handler = slack_notifier()
else:
handler = local_state_handler
k
Kevin Kho
10/22/2021, 7:54 PM
I think you can set the secret locally like
this▾
to mirror the Cloud Secret. Or you can turn off local secrets so that even local runs will pull the Cloud Secret
Kevin Kho
10/22/2021, 7:54 PM
You can set an env variable
"PREFECT__CLOUD__USE_LOCAL_SECRETS": "false"
j
Jacob Goldberg
10/22/2021, 8:09 PM
Thanks Kevin. good workaround, but i would actually prefer to have a different handler for local dev, and just figured the presence of the secret was a good way to determine that. No need for our team to get slack notifications while i mess things up during development
Jacob Goldberg
10/22/2021, 8:10 PM
Is there a better way to set the handler based on whether or not a run is being executed by prefect cloud?
k
Kevin Kho
10/22/2021, 8:16 PM
Ah I see what you mean. There is a context variable that does say if it’s a Cloud run. We can use that context in the state handler with an if-else to trigger the Slack notification. Let me look for it
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.