How do I compute the cold start of a scheduled job? #20777
-
Hello, We want to publish a metric to DataDog which is the cold start of a scheduled job. For us, this is defined as the difference between the scheduled timestamp (e.g., UTC midnight for a daily job), and the actual job start time (I think this would be the What is the best way to compute this in Python given a run ID? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @rob-apella when a job is scheduled, we apply a tag with the scheduled execution time. Between that and the something like @op
def compute_time_diff(context):
scheduled_time = context.instance.get_run_by_id(run_id).tags.get(".dagster/scheduled_execution_time")
run_start_time = datetime.datetime.fromtimestamp(
context.instance.get_run_record_by_id(run_id).start_time
).astimezone(datetime.timezone.utc)
context.log.info(f"SCHEDULED TIME: {scheduled_time}")
context.log.info(f"START TIME: {run_start_time}") |
Beta Was this translation helpful? Give feedback.
Hi @rob-apella when a job is scheduled, we apply a tag with the scheduled execution time. Between that and the
RUN_START
event you should have all the info you need! From therun_id
you can get aDagsterRun
object that contains the tagssomething like