-
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
8 changed files
with
182 additions
and
4 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
55 changes: 53 additions & 2 deletions
55
examples/airlift-federation-tutorial/airlift_federation_tutorial/dagster_defs/definitions.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 |
---|---|---|
@@ -1,5 +1,56 @@ | ||
from dagster import Definitions | ||
from dagster_airlift.core import ( | ||
AirflowBasicAuthBackend, | ||
AirflowInstance, | ||
build_airflow_polling_sensor_def, | ||
load_airflow_dag_asset_specs, | ||
) | ||
|
||
# Use this empty file to follow along with the tutorial | ||
upstream_airflow_instance = AirflowInstance( | ||
auth_backend=AirflowBasicAuthBackend( | ||
webserver_url="http://localhost:8081", | ||
username="admin", | ||
password="admin", | ||
), | ||
name="upstream", | ||
) | ||
|
||
defs = Definitions() | ||
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 = next( | ||
iter( | ||
load_airflow_dag_asset_specs( | ||
airflow_instance=downstream_airflow_instance, | ||
dag_selector_fn=lambda dag: dag.dag_id == "customer_metrics", | ||
) | ||
) | ||
) | ||
|
||
upstream_sensor = build_airflow_polling_sensor_def( | ||
mapped_assets=[load_customers_dag_asset], | ||
airflow_instance=upstream_airflow_instance, | ||
) | ||
downstream_sensor = build_airflow_polling_sensor_def( | ||
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], | ||
) |
Empty file.
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
from dagster import Definitions | ||
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 = next( | ||
iter( | ||
load_airflow_dag_asset_specs( | ||
airflow_instance=downstream_airflow_instance, | ||
dag_selector_fn=lambda dag: dag.dag_id == "customer_metrics", | ||
) | ||
) | ||
) | ||
|
||
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
42 changes: 42 additions & 0 deletions
42
examples/airlift-federation-tutorial/airlift_federation_tutorial_tests/test_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,42 @@ | ||
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 VERIFICATION_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": VERIFICATION_QUERY}, | ||
timeout=3, | ||
) | ||
assert response.status_code == 200 |
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