Thread
#prefect-community
    Varun Joshi

    Varun Joshi

    1 year ago
    Hey Prefecters, I don't want my flows to run between 2 AM to 10 AM from Mondays to Thursdays and 2 AM to 8 AM from Fridays to Sundays. I'm using the filters module provided by prefect for this. Assuming that I can do this,
    from prefect.schedules import IntervalSchedule, filters
    I made the below change in my code
    ist = pendulum.timezone('Asia/Calcutta')
    schedule = Schedule(
        clocks=[IntervalClock(interval=datetime.timedelta(minutes=1))],
        filters = filters.between_times(pendulum.time(6),pendulum.time(10))
    However, this doesn't seem to be working. Could someone please guide me on how to import filters and apply them to my schedule? Thank you, Varun
    Kevin Kho

    Kevin Kho

    1 year ago
    Hey @Varun Joshi! Schedule takes a list of clocks. Maybe it’s easier to pass a list of clocks.
    from prefect.schedules.clocks import CronClock
    
    week = CronClock(cron="0 6-18 * * 1-5")
    weekend = CronClock(cron="0 6-18/4 * * 0,6")
    
    clocks = [week, weekend]
    schedule = Schedule(clocks=clocks)
    Varun Joshi

    Varun Joshi

    1 year ago
    Great @Kevin Kho! Thanks a lot!
    Hey @Kevin Kho, where do I assign the start_date in this?
    Kevin Kho

    Kevin Kho

    1 year ago
    clock1   = clocks.IntervalClock(start_date=now, 
                                    interval=datetime.timedelta(minutes=1), 
                                    parameter_defaults={"p": "CLOCK 1"})
    Make two IntervalClocks and combine them to a schedule.
    Varun Joshi

    Varun Joshi

    1 year ago
    So now if I have to run flows between 10 AM to 2 AM on weekdays and 8 AM to 2 AM on weekends at a frequency of 3 mins, this will work right?
    from prefect.schedules.clocks import CronClock
    week = CronClock(cron="3 6-18 * * 1-5",start_date=datetime.datetime.now())
    weekend = CronClock(cron="3 6-18/4 * * 0,6")
    
    clocks = [week, weekend]
    schedule = Schedule(clocks=clocks)
    Kevin Kho

    Kevin Kho

    1 year ago
    I think you can’t do 10AM to 2AM with cron. You need to split that out to 10AM to midnight and then midnight to 2AM.
    Have you seen this tool: https://crontab.guru/ . It’s very helpful
    Varun Joshi

    Varun Joshi

    1 year ago
    Yes, I was working based on that itself.
    Thanks for the quick help. Really appreciate it 🙂