Dekel R
11/20/2022, 1:54 PMTaylor Curran
11/21/2022, 12:46 AMTaylor Curran
11/21/2022, 12:49 AMTaylor Curran
11/21/2022, 12:50 AMfrom prefect import flow
from prefect.blocks.notifications import SlackWebhook
@flow
def my_flow():
task_result_1 = follows_large_computation.submit()
if task_result_1.get_state().type != "COMPLETED":
print("Task Get State != Completed")
slack_webhook_block = SlackWebhook.load("prefect-notifications")
slack_webhook_block.notify("Task Failure from Prefect!")
^something like thisDekel R
11/21/2022, 9:26 AMdef send_slack_alert(messege: str):
slack_webhook_block = SlackWebhook.load("flows-status-slack- notifications")
slack_webhook_block.notify(messege)
And on a local run I get this -
{ValueError}Unable to find block document named flows-status-slack-notifications for block type slack-webhook
See the attached block,
I don’t get how this is suppose to work on local runs - this block is configured at our cloud account - the developer may be or may not be authenticated to our cloud account.
This is why I’m asking for similar functionality such as configuring a “conf.toml” file on local runs.Taylor Curran
11/21/2022, 2:11 PMTaylor Curran
11/21/2022, 2:57 PMDekel R
11/21/2022, 6:20 PMTaylor Curran
11/21/2022, 11:05 PMDekel R
12/08/2022, 10:00 AMTaylor Curran
12/08/2022, 3:51 PMTaylor Curran
12/08/2022, 3:57 PMDekel R
12/08/2022, 9:28 PMTaylor Curran
12/09/2022, 3:22 PMprefect orion start
I will make things easier if you define the slack webhook block in Python versus in the UI like shown below:
make_blocks.py
from prefect.blocks.notifications import SlackWebhook
local_webhook = SlackWebhook(url=dev_slack_webhook_url)
local_webhook.save("my_local_webhook")
^Save to either a local instance of orion then execute the flowDekel R
12/09/2022, 4:03 PMTaylor Curran
12/09/2022, 4:42 PMTaylor Curran
12/09/2022, 4:44 PMTaylor Curran
12/12/2022, 3:46 PMDekel R
12/12/2022, 4:17 PMfrom src.configurations import ENV
def send_slack_alert(messege: str):
try:
if ENV != 'LOCAL':
slack_webhook_block = SlackWebhook.load("flows-status-slack-notifications")
else:
slack_webhook_block = SlackWebhook(url=os.environ.get("SLACK_WEBHOOK_URL"))
slack_webhook_block.notify(messege)
except Exception as e:
<http://logger.info|logger.info>("Local run couldn't get slack webhook")
Both DEV and LOCAL have the same configuration in our case.
The DEV slack_webhook_url will get injected locally by using a .env file.
I think this solution is the most effortless for our Data Science team since they only need to add the webhook to their .env file.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.
Powered by