-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
338 additions
and
0 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+111 KB
docs/next/public/images/guides/dagster-pipes/subprocess-2-materialize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
...ts/docs_snippets/guides/dagster/dagster_pipes/subprocess/dagster_subprocess_env_extras.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,24 @@ | ||
import os | ||
import shutil | ||
|
||
from dagster import ( | ||
AssetExecutionContext, | ||
PipesSubprocessClient, | ||
asset, | ||
file_relative_path, | ||
) | ||
|
||
|
||
@asset | ||
def subprocess_asset( | ||
context: AssetExecutionContext, pipes_subprocess_client: PipesSubprocessClient | ||
): | ||
cmd = [shutil.which("python"), file_relative_path(__file__, "external_code.py")] | ||
return pipes_subprocess_client.run( | ||
command=cmd, | ||
context=context, | ||
extras={"foo": "bar"}, | ||
env={ | ||
"MY_ENV_VAR_IN_SUBPROCESS": os.environ["MY_ENV_VAR"], | ||
}, | ||
).get_results() |
30 changes: 30 additions & 0 deletions
30
...nippets/docs_snippets/guides/dagster/dagster_pipes/subprocess/dagster_subprocess_pipes.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,30 @@ | ||
# start_asset_marker | ||
import shutil | ||
|
||
from dagster import ( | ||
AssetExecutionContext, | ||
PipesSubprocessClient, | ||
asset, | ||
file_relative_path, | ||
) | ||
|
||
|
||
@asset | ||
def subprocess_asset( | ||
context: AssetExecutionContext, pipes_subprocess_client: PipesSubprocessClient | ||
): | ||
cmd = [shutil.which("python"), file_relative_path(__file__, "external_code.py")] | ||
return pipes_subprocess_client.run(command=cmd, context=context).get_results() | ||
|
||
|
||
# end_asset_marker | ||
|
||
# start_definitions_marker | ||
|
||
from dagster import Definitions | ||
|
||
defs = Definitions( | ||
assets=[subprocess_asset], | ||
resources={"pipes_subprocess_client": PipesSubprocessClient()}, | ||
) | ||
# end_definitions_marker |
23 changes: 23 additions & 0 deletions
23
...ocs_snippets/guides/dagster/dagster_pipes/subprocess/dagster_subprocess_pipes_finished.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,23 @@ | ||
import shutil | ||
|
||
from dagster import ( | ||
AssetExecutionContext, | ||
Definitions, | ||
PipesSubprocessClient, | ||
asset, | ||
file_relative_path, | ||
) | ||
|
||
|
||
@asset | ||
def subprocess_asset( | ||
context: AssetExecutionContext, pipes_subprocess_client: PipesSubprocessClient | ||
): | ||
cmd = [shutil.which("python"), file_relative_path(__file__, "external_code.py")] | ||
return pipes_subprocess_client.run(command=cmd, context=context).get_results() | ||
|
||
|
||
defs = Definitions( | ||
assets=[subprocess_asset], | ||
resources={"pipes_subprocess_client": PipesSubprocessClient()}, | ||
) |
23 changes: 23 additions & 0 deletions
23
..._snippets/docs_snippets/guides/dagster/dagster_pipes/subprocess/external_code_finished.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,23 @@ | ||
import pandas as pd | ||
from dagster_pipes import PipesContext, open_dagster_pipes | ||
|
||
|
||
def main(): | ||
orders_df = pd.DataFrame({"order_id": [1, 2], "item_id": [432, 878]}) | ||
total_orders = len(orders_df) | ||
# get the Dagster Pipes context | ||
context = PipesContext.get() | ||
# send structured metadata back to Dagster | ||
context.report_asset_materialization(metadata={"total_orders": total_orders}) | ||
# report data quality check result back to Dagster | ||
context.report_asset_check( | ||
asset_key="my_asset", | ||
passed=orders_df[["item_id"]].notnull().all().bool(), | ||
check_name="no_empty_order_check", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# connect to Dagster Pipes | ||
with open_dagster_pipes() as context: | ||
main() |