Alec Ryan
04/21/2022, 4:22 PMjohann
04/21/2022, 5:17 PMAlec Ryan
04/21/2022, 5:20 PMjohann
04/21/2022, 5:49 PMowen
04/21/2022, 5:59 PMasset_event.dagster_event.logging_tags.get("dagster/partition")
Alec Ryan
04/21/2022, 6:00 PMowen
04/21/2022, 6:05 PMDagster Bot
04/21/2022, 6:06 PMAlec Ryan
04/21/2022, 6:06 PMfrom dagster import AssetKey, asset_sensor
def create_dbt_sensor(key, job):
@asset_sensor(
asset_key=AssetKey(key),
job=job
)
def dbt_sensor(context, asset_event):
yield RunRequest(
run_key=context.cursor,
run_config={
"ops": {
"read_materialization": {
"config": {
"asset_key": asset_event.dagster_event.asset_key.path,
"run_date" : asset_event.dagster_event.logging_tags.get("dagster/partition")
}
}
}
},
)
return dbt_sensor
owen
04/21/2022, 11:31 PMAlec Ryan
04/22/2022, 1:49 AMowen
04/22/2022, 4:43 PM@asset_sensor(...)
def my_sensor(context, asset_event):
asset_partition = ... # either logging tags thing or asset_event.dagster_event.partition, should be identical
run_config = ... # some way of varying the behavior of your dbt job based on this value
yield RunRequest(...)
One way of creating some run config that varies the behavior of the dbt job based on the partition is to just set a value in the resource config for the dbt_cli_resource, and another would be to do something like what you show above, where you set some op config values and read them inside the op. was there something about that solution that didn't work? (I'm assuming read_materializations is a custom op you wrote)Alec Ryan
04/22/2022, 5:34 PMowen
04/22/2022, 10:15 PMAlec Ryan
04/23/2022, 12:59 PMowen
04/25/2022, 4:06 PMAlec Ryan
04/25/2022, 5:29 PMowen
04/25/2022, 11:02 PM# query the Dagster instance for information about the upstream run
upstream_run = context.instance.get_run_by_id(asset_event.run_id)
# get the run config from that upstream run
upstream_run_config = upstream_run.run_config
# ... parse the run config to figure out the date
I'll admit, it's a bit ugly, but it should do the jobAlec Ryan
04/26/2022, 12:14 AMowen
04/26/2022, 4:17 PMAlec Ryan
04/26/2022, 4:37 PM