Wei Mei
03/29/2022, 8:51 PMdate
and today
context in a task, but getting None.
date = prefect.context.get("date")
today = prefect.context.get("today")
def get_data():
print(f"{date}")
print(today)
Anna Geller
Wei Mei
03/29/2022, 8:58 PM@task
and reran, the output in the terminal is still None.Anna Geller
from prefect import Flow, task
import prefect
@task(log_stdout=True)
def hello_world():
date = prefect.context.get("date")
today = prefect.context.get("today")
print(f"Today {today} is {date}")
with Flow("flow_giving_you_some_context") as flow:
hw = hello_world()
if __name__ == '__main__':
flow.run()
Anna Geller
[2022-03-29 23:00:26+0200] INFO - prefect.FlowRunner | Beginning Flow run for 'flow_giving_you_some_context'
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Task 'hello_world': Starting task run...
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Today 2022-03-29 is 2022-03-29T21:00:26.879376+00:00
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Task 'hello_world': Finished task run for task with final state: 'Success'
[2022-03-29 23:00:26+0200] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
Wei Mei
03/29/2022, 9:03 PMWei Mei
03/29/2022, 9:04 PMWei Mei
03/29/2022, 9:04 PM