-
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.
- Loading branch information
Showing
8 changed files
with
72 additions
and
63 deletions.
There are no files selected for viewing
34 changes: 5 additions & 29 deletions
34
examples/project_atproto_dashboard/project_atproto_dashboard/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,33 +1,9 @@ | ||
"""The Bluesky servers impose rate limiting of the following specification.""" | ||
|
||
import dagster as dg | ||
from dagster_aws.s3 import S3Resource | ||
|
||
from project_atproto_dashboard.assets import ( | ||
actor_feed_snapshot, | ||
dbt_bluesky, | ||
dbt_resource, | ||
starter_pack_snapshot, | ||
) | ||
from project_atproto_dashboard.resources import ATProtoResource | ||
|
||
atproto_resource = ATProtoResource( | ||
login=dg.EnvVar("BSKY_LOGIN"), password=dg.EnvVar("BSKY_APP_PASSWORD") | ||
) | ||
|
||
s3_resource = S3Resource( | ||
endpoint_url=dg.EnvVar("AWS_ENDPOINT_URL"), | ||
aws_access_key_id=dg.EnvVar("AWS_ACCESS_KEY_ID"), | ||
aws_secret_access_key=dg.EnvVar("AWS_SECRET_ACCESS_KEY"), | ||
region_name="auto", | ||
) | ||
|
||
import project_atproto_dashboard.ingestion.definitions as ingestion_definitions | ||
import project_atproto_dashboard.modeling.definitions as modeling_definitions | ||
|
||
defs = dg.Definitions( | ||
assets=[starter_pack_snapshot, actor_feed_snapshot, dbt_bluesky], | ||
resources={ | ||
"atproto_resource": atproto_resource, | ||
"s3_resource": s3_resource, | ||
"dbt": dbt_resource, | ||
}, | ||
defs = dg.Definitions.merge( | ||
ingestion_definitions.defs, | ||
modeling_definitions.defs, | ||
) |
File renamed without changes.
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
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
45 changes: 45 additions & 0 deletions
45
examples/project_atproto_dashboard/project_atproto_dashboard/modeling/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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Any, Mapping, Optional | ||
|
||
import dagster as dg | ||
from dagster_dbt import DagsterDbtTranslator, DbtCliResource, DbtProject, dbt_assets | ||
|
||
dbt_project = DbtProject( | ||
project_dir=Path(__file__).joinpath("..", "..", "..", "dbt_project").resolve(), | ||
target=os.getenv("DBT_TARGET"), | ||
) | ||
dbt_project.prepare_if_dev() | ||
dbt_resource = DbtCliResource(project_dir=dbt_project) | ||
|
||
|
||
class CustomizedDagsterDbtTranslator(DagsterDbtTranslator): | ||
def get_group_name(self, dbt_resource_props: Mapping[str, Any]) -> Optional[str]: | ||
asset_path = dbt_resource_props["fqn"][1:-1] | ||
if asset_path: | ||
return "_".join(asset_path) | ||
return "default" | ||
|
||
def get_asset_key(self, dbt_resource_props): | ||
resource_type = dbt_resource_props["resource_type"] | ||
name = dbt_resource_props["name"] | ||
if resource_type == "source": | ||
return dg.AssetKey(name) | ||
else: | ||
return super().get_asset_key(dbt_resource_props) | ||
|
||
|
||
@dbt_assets( | ||
manifest=dbt_project.manifest_path, | ||
dagster_dbt_translator=CustomizedDagsterDbtTranslator(), | ||
) | ||
def dbt_bluesky(context: dg.AssetExecutionContext, dbt: DbtCliResource): | ||
yield from (dbt.cli(["build"], context=context).stream().fetch_row_counts()) | ||
|
||
|
||
defs = dg.Definitions( | ||
assets=[dbt_bluesky], | ||
resources={ | ||
"dbt": dbt_resource, | ||
}, | ||
) |