https://dagster.io/ logo
#ask-community
Title
# ask-community
m

Miguel Caballero Pinto

06/16/2023, 2:06 PM
Hi there! How would you check if a particular asset is already in the middle of a materialization inside a sensor executrion? I tried using
context.instance.get_latest_materialization_event
but I couldn’t figure out how check that the event is that a materialization is running. Thanks!
I think I found a pattern on how to solve my scenario, which is not running the sensor when an asset is materializing (not when a job is running, as the job can materialize multiple assets)
o

owen

06/16/2023, 9:27 PM
sounds like you have the situation handled -- internally what we do is use instance.get_asset_records([asset_key]), which will give us an AssetRecord for that key. asset_record.asset_entry has a last_run_id field, which we can then grab the run for to see if the latest run is in progress, finished, or failed
❤️ 1
m

Miguel Caballero Pinto

07/24/2023, 9:48 AM
Sorry for the delay, I tried this but I found an issue. If the asset is run as part a group with other assets, checking the last run status won’t give me completed until all assets are materialized. I need to know when the asset is finished materializing even if the run is still running. Does this make sense? Is there a way to achieve this?
@owen Do you know how we could check if a particular asset is materializing without getting it confused with the whole group run? This would help us immesevely on parallelizing jobs and I can’t see how a solution from the documentation.
o

owen

07/27/2023, 8:52 PM
ah I see what you mean. one addition to that logic would be: 1. get_asset_records([asset_key]) to get the AssetRecord for a given asset 2. look at the
last_run_id
field, which will tell you the latest run that asset has been a part of 3. check the
last_materialization_record
field on the asset record. this record will have a run_id field in it. if the last materialization record has the same run_id as the last_run_id, then this asset has been materialized as part of that run (so it's not in progress). 4. if it has a different run_id from
last_run_id
, then this means either that run is still in progress, or it failed. to tell the difference between these two cases you can check the status of the run
4 Views