https://dagster.io/ logo
Title
w

Will Gunadi

03/05/2022, 12:05 AM
Is there an equivalent of context.scheduled_execution_time for jobs that are not run via the scheduler? Context: When I run a job manually via dagit, the above variable don't exist in the context.
p

prha

03/05/2022, 12:31 AM
Hi Will. I believe that
scheduled_execution_time
only exists on the ScheduleEvaluationContext (docs link). During the actual job execution, you would have access to an OpExecutionContext (docs link) regardless of how you kicked off the job (either manually or by schedule).
Kind of depends on what you’re doing, but if you’re trying to map the scheduled_execution_time to a run config, you could try just using the current time
w

Will Gunadi

03/05/2022, 12:38 AM
Just thinking intuitively, there should be something available within the context object that tells me what time is the job started, no?
d

daniel

03/05/2022, 3:05 AM
we do store when the run started in the storage, but there isn't a single-property way to fetch it currently from the OpExecutionContext. Under the hood it could be called with something like
context.instance.get_run_records(RunsFilter(run_ids=[context.run_id]))[0].start_time
but that's pretty verbose and uses some internal APIs - exposing this in a more user-friendly way makes sense to me
w

Will Gunadi

03/05/2022, 3:27 PM
That is interesting that you can get to the record in the runs table that way (I use Postgres to store the runs, so I recognize the field names). Thank you! And yes, I think basically anything on that run record should be available at the job/op level during run time in a less verbose (and error prone) way.
@daniel how do I import RunsFilter ? It's not listed in the dagster init.py
d

daniel

03/07/2022, 4:56 PM
Yeah, that's the 'uses some internal APIs' part. You'd need to do
from dagster.core.storage.pipeline_run import RunsFilter
and there's more risk of it changing between Dagster releases since it's not considered part of the public facing API. @Dagster Bot issue provide a fully supported way to get the job start time from an OpExecutionContext
d

Dagster Bot

03/07/2022, 4:56 PM
w

Will Gunadi

03/07/2022, 4:58 PM
@daniel Now that's a good use of a Slack bot 😄
:next-level-daggy: 1