Alex Kan
08/14/2023, 3:16 PMload_assets_from_dbt_project
• We set an owner
meta tag within sources.yml
for our models
• We want to tag these owners using make_slack_on_run_failure_sensor
. How can we access the tags via the context
within a custom text_fn
that’s passed to make_slack_on_run_failure_sensor
?
Our runs also typically contain multiple assets, potentially with multiple owners. Could we programmatically determine the owners of only the subset of models that failed in the run? (edited)rex
08/14/2023, 3:24 PM@dbt_assets
, since you have access to customize the compute function, you can invoke slack in the body of your assets definition. We showed this in our release livestream a while back:
The basic code is here. You can imagine that you could just:
1. Get the run_results_json
to get failed models
2. Look into the manifest object to get the meta
associated with each failed model
3. Send a Slack message for each owner in (2)
@dbt_assets(manifest=dbt_manifest_path)
def jaffle_shop_dbt_assets(
context: OpExecutionContext, dbt: DbtCliResource, slack: SlackResource
):
dbt_build_invocation = dbt.cli(["build"], context=context)
yield from dbt_build_invocation.stream()
run_results_json = dbt_build_invocation.get_artifact("run_results.json")
materialized_models_text = ""
for result in run_results_json["results"]:
if result["status"] == "success":
materialized_models_text += (
f"- `{result['unique_id']}`: {result['message']}\n"
)
slack.get_client().chat_postMessage(
channel="team-nucleus-data-platform",
text=(
"The following dbt nodes have successfully materialized:\n"
+ materialized_models_text
),
)
Alex Kan
08/14/2023, 3:24 PMAlex Kan
08/14/2023, 3:25 PMrex
08/14/2023, 3:26 PM