Hi All, I have a prefect job scheduled everyday, ...
# ask-community
h
Hi All, I have a prefect job scheduled everyday, and it has a default_date parameter.
Copy code
with Flow("impact partners",schedule=schedule) as flow:
    
    #setting default date to today - 1 to get the records from previous day
    default_date = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')

    start_date = Parameter('start_date', default=default_date)
    end_date = Parameter('end_date', default=default_date)

    records = get_impact_records(start_date,end_date)
    impact_partners = rename_columns(records)
    upload(data=impact_partners)
    
if __name__ == "__main__":
    main(flow)
i think the default_date section gets defined at compile time rather than run time, So, that is why it is static. And the job get run for 2021-09-23 everyday. What is the best way to make default_date dynamic. Thanks
k
Hey @Haseeb Ahmad, you are right the the parameter gets evaluated at build time. There are two ways to get this to evaluate during runtime. The first one is storing your Flow as a script so that it gets evaluated during runtime. The second one is to take in a number as the Parameter and then create another task that subtracts the number and returns the date. For example, you can set the default at 0 and then the task returns
(datetime.today() - timedelta(days=0)).strftime('%Y-%m-%d')
h
Hey Thanks a lot @Kevin Kho