Hi. I'd like to check the meaning of `date` in pre...
# ask-community
j
Hi. I'd like to check the meaning of
date
in prefect context. The docs say "an actual datetime object representing the current time". The datetime value appears to be the same value across all tasks within a flow- so I assuem this is actually the start time of the flow? This behaviour is what I want, but want to confirm my assumption.
local run output (3 sequential identical tasks. Each prints
prefect.context.get("date")
, then sleeps for 1.1 seconds)
Copy code
test.run()
[2021-11-26 12:41:53+0000] INFO - prefect.FlowRunner | Beginning Flow run for 'test'
[2021-11-26 12:41:53+0000] DEBUG - prefect.FlowRunner | Using executor type LocalExecutor
[2021-11-26 12:41:53+0000] DEBUG - prefect.FlowRunner | Flow 'test': Handling state change from Scheduled to Running
[2021-11-26 12:41:53+0000] INFO - prefect.TaskRunner | Task 'thing': Starting task run...
[2021-11-26 12:41:53+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Pending to Running
[2021-11-26 12:41:53+0000] DEBUG - prefect.TaskRunner | Task 'thing': Calling task.run() method...
prefect.context.get("date"): 2021-11-26T12:41:53.398890+00:00
[2021-11-26 12:41:54+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Running to Success
[2021-11-26 12:41:54+0000] INFO - prefect.TaskRunner | Task 'thing': Finished task run for task with final state: 'Success'
[2021-11-26 12:41:54+0000] INFO - prefect.TaskRunner | Task 'thing': Starting task run...
[2021-11-26 12:41:54+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Pending to Running
[2021-11-26 12:41:54+0000] DEBUG - prefect.TaskRunner | Task 'thing': Calling task.run() method...
prefect.context.get("date"): 2021-11-26T12:41:53.398890+00:00
[2021-11-26 12:41:55+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Running to Success
[2021-11-26 12:41:55+0000] INFO - prefect.TaskRunner | Task 'thing': Finished task run for task with final state: 'Success'
[2021-11-26 12:41:55+0000] INFO - prefect.TaskRunner | Task 'thing': Starting task run...
[2021-11-26 12:41:55+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Pending to Running
[2021-11-26 12:41:55+0000] DEBUG - prefect.TaskRunner | Task 'thing': Calling task.run() method...
prefect.context.get("date"): 2021-11-26T12:41:53.398890+00:00
[2021-11-26 12:41:56+0000] DEBUG - prefect.TaskRunner | Task 'thing': Handling state change from Running to Success
[2021-11-26 12:41:56+0000] INFO - prefect.TaskRunner | Task 'thing': Finished task run for task with final state: 'Success'
[2021-11-26 12:41:56+0000] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
[2021-11-26 12:41:56+0000] DEBUG - prefect.FlowRunner | Flow 'test': Handling state change from Running to Success
Out[23]: <Success: "All reference tasks succeeded.">
a
@John Shearer yes, I can confirm that. The “scheduled_start_time” is when the flow is scheduled to run, “date” is when the flow actually starts the execution. Flow I used to test this:
Copy code
import prefect
from prefect import task, Flow
import time


@task(log_stdout=True)
def get_date_and_scheduled_start_time():
    print(prefect.context.get("date"))
    print(prefect.context.get("scheduled_start_time"))
    time.sleep(2)


with Flow("context") as flow:
    t1 = get_date_and_scheduled_start_time()
    t2 = get_date_and_scheduled_start_time()
    t3 = get_date_and_scheduled_start_time()
    t4 = get_date_and_scheduled_start_time()
    t1.set_downstream(t2)
    t2.set_downstream(t3)
    t3.set_downstream(t4)
And Cloud logs:
both scheduled_start_time and date are exactly the same for all tasks
j
that's great. just what I wanted.
🙌 1
Might be worth clarifying those in the docs
a
good idea!
❤️ 1