https://dagster.io/ logo
Title
p

Pablo Beltran

03/24/2023, 7:37 PM
I want to create an individual job for every asset in an asset group how would I iterate over all the assets in an asset group and make a job for each of them.
j

jamie

03/24/2023, 7:38 PM
hey @Pablo Beltran how are you making your asset group?
p

Pablo Beltran

03/24/2023, 7:39 PM
They are dbt assets and I have made it so that the asset group is determined by their dir path in the dbt project.
j

jamie

03/24/2023, 7:55 PM
ok. i haven’t tried this myself, but something like this might work
dbt_assets = load_assets_from_dbt_project(...)

def make_dbt_asset_job(asset_def):
    return define_asset_job(name=f"{asset_def.name}_job", selection=[asset_def], <other_args>)

defs = Definitions(
    assets=dbt_assets,
    jobs=[make_dbt_asset_job(asset_def) for asset_def in dbt_assets]
)
p

Pablo Beltran

03/24/2023, 8:47 PM
Thanks! I got it working now. Needed to make it slightly different:
def make_dbt_asset_job(asset_key):
    return define_asset_job(name=f"{asset_key.to_python_identifier()}_job", selection=AssetSelection.keys(asset_key), <other_args>)

defs = Definitions(
    assets=dbt_assets,
    jobs=[make_dbt_asset_job(asset_key) for asset_def in dbt_assets[0].asset_keys]
)
👍 1