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

Amit Arie

08/03/2022, 6:02 PM
Hi all 🙂 Is there a way to extract the duration of specific op, via
StepExecutionContext
or
HookContext
?
🤖 1
m

Matthew Karas

08/03/2022, 6:12 PM
Yes please - I'd like to know this too. I was trying to write a decorator to do this - but it wasn't working when I put the wrapped op in a graph
a

Amit Arie

08/03/2022, 6:12 PM
@Roei Jacobovich cc
o

owen

08/04/2022, 9:08 PM
hi @Amit Arie and @Matthew Karas! Sorry for the slow reply. If context is a
StepExecutionContext
, you can query the Dagster database for statistics about your step like this:
Copy code
step_stats = context.instance.get_run_step_stats(
    run_id=context.run_id,
    step_keys=[<step key you care about>],
)[0]

duration = step_stats.end_time - step_stats.start_time
if you have a
HookContext
, our API doesn't currently provide public access to the underlying step context (not sure exactly why that is), but if you need to you can access the instance using
context._step_execution_context.instance
. Just be aware that, because this is a private property, its name might change in the future (although that's unlikely)
a

Amit Arie

08/05/2022, 11:57 AM
Thanks, @owen! does the Dagster’s stats DB will be always up to date, during the hook phase?
o

owen

08/05/2022, 9:52 PM
hi @Amit Arie! the STEP_STARTED / STEP_FAILED event from a step is emitted before the hook code executes, and so it should be present in the database at the time you make that query.
D 1
❤️ 1
2 Views