Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dagster-airlift] better code example highlighting in peer stage #27534

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from dagster_airlift.core import (
AirflowBasicAuthBackend,
AirflowInstance,
build_defs_from_airflow_instance,
)
import dagster_airlift.core as dg_airlift_core

defs = build_defs_from_airflow_instance(
airflow_instance=AirflowInstance(
defs = dg_airlift_core.build_defs_from_airflow_instance(
airflow_instance=dg_airlift_core.AirflowInstance(
# other backends available (e.g. MwaaSessionAuthBackend)
auth_backend=AirflowBasicAuthBackend(
auth_backend=dg_airlift_core.AirflowBasicAuthBackend(
webserver_url="http://localhost:8080",
username="admin",
password="admin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
import os
from pathlib import Path

from dagster import AssetCheckResult, AssetCheckSeverity, AssetKey, Definitions, asset_check
from dagster_airlift.core import (
AirflowBasicAuthBackend,
AirflowInstance,
build_defs_from_airflow_instance,
)
import dagster as dg
import dagster_airlift.core as dg_airlift_core


# highlight-start
# Attach a check to the DAG representation asset, which will be executed by Dagster
# any time the DAG is run in Airflow
@asset_check(asset=AssetKey(["airflow_instance_one", "dag", "rebuild_customers_list"]))
def validate_exported_csv() -> AssetCheckResult:
@dg.asset_check(asset=dg.AssetKey(["airflow_instance_one", "dag", "rebuild_customers_list"]))
def validate_exported_csv() -> dg.AssetCheckResult:
csv_path = Path(os.environ["TUTORIAL_EXAMPLE_DIR"]) / "customers.csv"

if not csv_path.exists():
return AssetCheckResult(passed=False, description=f"Export CSV {csv_path} does not exist")
return dg.AssetCheckResult(
passed=False, description=f"Export CSV {csv_path} does not exist"
)

rows = len(csv_path.read_text().split("\n"))
if rows < 2:
return AssetCheckResult(
return dg.AssetCheckResult(
passed=False,
description=f"Export CSV {csv_path} is empty",
severity=AssetCheckSeverity.WARN,
severity=dg.AssetCheckSeverity.WARN,
)

return AssetCheckResult(
return dg.AssetCheckResult(
passed=True,
description=f"Export CSV {csv_path} exists",
metadata={"rows": rows},
)


defs = build_defs_from_airflow_instance(
airflow_instance=AirflowInstance(
# highlight-end


defs = dg_airlift_core.build_defs_from_airflow_instance(
airflow_instance=dg_airlift_core.AirflowInstance(
# other backends available (e.g. MwaaSessionAuthBackend)
auth_backend=AirflowBasicAuthBackend(
auth_backend=dg_airlift_core.AirflowBasicAuthBackend(
webserver_url="http://localhost:8080",
username="admin",
password="admin",
),
name="airflow_instance_one",
),
defs=Definitions(asset_checks=[validate_exported_csv]),
# highlight-start
# Pass a Definitions object containing the relevant check, so that it is attached to the DAG
# asset.
defs=dg.Definitions(asset_checks=[validate_exported_csv]),
# highlight-end
)