-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] - Graph-backed assets [CON-34] (#8174)
* First pass * Add example * Review comments * Remove unused imports; run snapshot * Run isort
- Loading branch information
1 parent
eea9a77
commit 003bfc0
Showing
2 changed files
with
92 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
50 changes: 50 additions & 0 deletions
50
examples/docs_snippets/docs_snippets/concepts/assets/graph_backed_asset.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,50 @@ | ||
from unittest import mock | ||
|
||
from pandas import DataFrame | ||
|
||
from dagster import AssetGroup, AssetsDefinition, ResourceDefinition, graph, op | ||
|
||
|
||
def create_db_connection(): | ||
return "yay" | ||
|
||
|
||
# start example | ||
|
||
|
||
@op(required_resource_keys={"slack"}) | ||
def fetch_files_from_slack(context) -> DataFrame: | ||
files = context.resources.slack.files_list(channel="#random") | ||
return DataFrame( | ||
[ | ||
{ | ||
"id": file.get("id"), | ||
"created": file.get("created"), | ||
"title": file.get("title"), | ||
"permalink": file.get("permalink"), | ||
} | ||
for file in files | ||
] | ||
) | ||
|
||
|
||
@op | ||
def store_files(files): | ||
return files.to_sql(name="slack_files", con=create_db_connection()) | ||
|
||
|
||
@graph | ||
def store_slack_files_in_sql(): | ||
store_files(fetch_files_from_slack()) | ||
|
||
|
||
graph_asset = AssetsDefinition.from_graph(store_slack_files_in_sql) | ||
|
||
# end example | ||
|
||
slack_mock = mock.MagicMock() | ||
|
||
store_slack_files = AssetGroup( | ||
[graph_asset], | ||
resource_defs={"slack": ResourceDefinition.hardcoded_resource(slack_mock)}, | ||
).build_job("store_slack_files") |
003bfc0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dagster – ./docs/next
dagster.vercel.app
dagster-elementl.vercel.app
docs.dagster.io
new-docs.dagster.io
dagster-git-master-elementl.vercel.app