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

Clovis Warlop

04/11/2023, 3:47 AM
Is there anyway in an asset to access the total time it took to run the asset?
c

claire

04/11/2023, 6:03 PM
Hi Clovis. In an asset if you want to see how long it took the prior run for the asset to run, you could do something like this:
Copy code
event_records = context.instance.get_event_records(
        EventRecordsFilter(
            DagsterEventType.ASSET_MATERIALIZATION, asset_key=AssetKey("some_asset")
        ),
        limit=1,
    )
    if event_records:
        step_stats = next(
            iter(context.instance.get_run_step_stats(event_records[0].run_id, ["some_asset"]))
        )
        step_time = step_stats.end_time - step_stats.start_time
        <http://context.log.info|context.log.info>(f"step_time: {step_time}")
which basically fetches the latest run id for a given asset, and fetches the step stats from the run to calculate how long the step took
3 Views