Hi all, i have this problem. When i use datetime o...
# ask-community
l
Hi all, i have this problem. When i use datetime or pendulum library, and then register a flow, this will always take register datetime , not the current time of the running flow. My code. Any suggest?
Copy code
import prefect 
import pendulum

cron_now = pendulum.now()
str_date = cron_now.strftime('%Y%m%d_%H%M%S')
custom_schedule = CronSchedule("0 9 * * 0", start_date=cron_now)


def slack(text):
	data = '{"channel":"XXX","text":"%s: %s"}' % (str_date, text)

@task
def task():
	## do something
	##call_slack
	slack("Hello")
	
with Flow("fact_czenk", schedule=custom_schedule) as flow:
	task = task()
	
flow.register()
s
You probably want to either: 1. define str_date and cron_now inside the task itself 2. define str_date and cron_now in the actual flow (inside the context manager) Prefect is functioning as expected here, the task is executing and using a pre-defined global variable.
upvote 1
l
thanks i will try it
@Samuel Hinton Thanks for your help. It's working
s
The best fix is an easy fix 🙂
🙌🏼 1