https://prefect.io logo
p

Prateek Saigal

01/21/2022, 5:12 PM
Hi, Just arrived. I have registered a flow and have added the CronSchedule. It gets scheduled on the right time but it is picking up the wrong date
Copy code
flow.schedule = CronSchedule("49 21 * * 1-5",start_date=pendulum.datetime(2022, 1, 1, tz="Asia/Kolkata"),)

flow.register(
      project_name=project_name,
      idempotency_key=flow.serialized_hash(),
      labels=["test"],
    )
What could be the reason for this?
k

Kevin Kho

01/21/2022, 5:13 PM
What date is it picking up for you?
p

Prateek Saigal

01/21/2022, 5:14 PM
So I had registered the flow yesterday and yesterday it worked fine
But today it is picking up the yesterday's date only
k

Kevin Kho

01/21/2022, 5:15 PM
Is that related to your schedule or do you have a date Parameter in your flow?
p

Prateek Saigal

01/21/2022, 5:15 PM
Copy code
# -- Write you flows here
  with Flow(workflow_name) as flow:
    today_date = datetime.datetime.now(pytz.timezone('Asia/Kolkata')).strftime("%Y%m%d")
    date = Parameter("date", default=today_date
k

Kevin Kho

01/21/2022, 5:16 PM
Yeah exactly. That date is fixed during the registration time. You need to make it a task so that it’s evaluated during runtime.
Copy code
@task
def get_date(val):
    if val == None:
        return datetime.datetime.now(pytz.timezone('Asia/Kolkata')).strftime("%Y%m%d")

with Flow(...) as flow:
    the_date = Parameter("today", default=None)
    the_date = get_date(the_date)
p

Prateek Saigal

01/21/2022, 5:20 PM
Thanks Kevin - let me try this and get back
k

Kevin Kho

01/21/2022, 5:20 PM
The issue is the default is evaluated immediately during registration
5 Views