-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dagster-airlift] Add initial stage to add specs to federation tutorial
- Loading branch information
Showing
7 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
61 changes: 61 additions & 0 deletions
61
...airlift-federation-tutorial/airlift_federation_tutorial/dagster_defs/stages/with_specs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from dagster import Definitions | ||
from dagster._core.definitions.asset_spec import replace_attributes | ||
from dagster_airlift.core import ( | ||
AirflowBasicAuthBackend, | ||
AirflowInstance, | ||
build_airflow_polling_sensor, | ||
load_airflow_dag_asset_specs, | ||
) | ||
|
||
upstream_airflow_instance = AirflowInstance( | ||
auth_backend=AirflowBasicAuthBackend( | ||
webserver_url="http://localhost:8081", | ||
username="admin", | ||
password="admin", | ||
), | ||
name="upstream", | ||
) | ||
|
||
downstream_airflow_instance = AirflowInstance( | ||
auth_backend=AirflowBasicAuthBackend( | ||
webserver_url="http://localhost:8082", | ||
username="admin", | ||
password="admin", | ||
), | ||
name="downstream", | ||
) | ||
|
||
load_customers_dag_asset = next( | ||
iter( | ||
load_airflow_dag_asset_specs( | ||
airflow_instance=upstream_airflow_instance, | ||
dag_selector_fn=lambda dag: dag.dag_id == "load_customers", | ||
) | ||
) | ||
) | ||
customer_metrics_dag_asset = replace_attributes( | ||
next( | ||
iter( | ||
load_airflow_dag_asset_specs( | ||
airflow_instance=downstream_airflow_instance, | ||
dag_selector_fn=lambda dag: dag.dag_id == "customer_metrics", | ||
) | ||
) | ||
# Add a dependency on the load_customers_dag_asset | ||
), | ||
deps=[load_customers_dag_asset], | ||
) | ||
|
||
upstream_sensor = build_airflow_polling_sensor( | ||
mapped_assets=[load_customers_dag_asset], | ||
airflow_instance=upstream_airflow_instance, | ||
) | ||
downstream_sensor = build_airflow_polling_sensor( | ||
mapped_assets=[customer_metrics_dag_asset], | ||
airflow_instance=downstream_airflow_instance, | ||
) | ||
|
||
defs = Definitions( | ||
assets=[load_customers_dag_asset, customer_metrics_dag_asset], | ||
sensors=[upstream_sensor, downstream_sensor], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
examples/airlift-federation-tutorial/airlift_federation_tutorial_tests/test_specs_stage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import subprocess | ||
from typing import Generator | ||
|
||
import pytest | ||
import requests | ||
from airlift_federation_tutorial_tests.conftest import ORIG_DEFS_FILE, makefile_dir, replace_file | ||
from dagster_airlift.in_airflow.gql_queries import ASSET_NODES_QUERY | ||
from dagster_airlift.test.shared_fixtures import stand_up_dagster | ||
|
||
STAGE_FILE = ORIG_DEFS_FILE.parent / "stages" / "with_specs.py" | ||
|
||
|
||
@pytest.fixture | ||
def completed_stage() -> Generator[None, None, None]: | ||
with replace_file(ORIG_DEFS_FILE, STAGE_FILE): | ||
yield | ||
|
||
|
||
@pytest.fixture(name="dagster_dev") | ||
def dagster_fixture( | ||
upstream_airflow: subprocess.Popen, downstream_airflow: subprocess.Popen, completed_stage: None | ||
) -> Generator[subprocess.Popen, None, None]: | ||
process = None | ||
try: | ||
with stand_up_dagster( | ||
dagster_dev_cmd=["make", "-C", str(makefile_dir()), "dagster_run"], | ||
port=3000, | ||
) as process: | ||
yield process | ||
finally: | ||
if process: | ||
process.terminate() | ||
|
||
|
||
def test_with_specs(dagster_dev: subprocess.Popen) -> None: | ||
response = requests.post( | ||
# Timeout in seconds | ||
"http://localhost:3000/graphql", | ||
json={"query": ASSET_NODES_QUERY}, | ||
timeout=3, | ||
) | ||
assert response.status_code == 200 | ||
assert len(response.json()["data"]["assetNodes"]) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters