https://prefect.io logo
Title
v

Vadym Dytyniak

09/20/2022, 2:37 PM
Hi. Does RRuleSchedule support something like? I was able to deploy the flow, but don't see any scheduled flow runs.
RDATE:20220920T200000Z,20220921T133000Z
UI says: 'Every year' schedule:
j

James Sopkin

09/20/2022, 2:56 PM
hi Vadym, check out the docs here. The example provided is this
schedule:
  rrule: 'FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20240730T040000Z'
Could you clarify what you are trying to do with the rrule schedule?
v

Vadym Dytyniak

09/20/2022, 3:01 PM
Sure. I used DatesClock to run flows using custom calendar and now I am looking for the solution in Prefect 2.
j

James Sopkin

09/20/2022, 3:08 PM
Ahh okay, I don't believe rrule would be appropriate for that use case. Rrule uses recurring calendar logic- for example- the first Tuesday of every month. Let me follow up on this. I'll try to find if there is a similar datesclock or custom solution that exists
v

Vadym Dytyniak

09/20/2022, 3:12 PM
Thanks a lot! I was trying to implement custom schedule, but pydantic validation does not allow custom model fields.
class CalendarSchedule(PrefectBaseModel):

    run_times: list[pendulum.Time]
    calendar_id: str

    async def get_dates(
        self,
        n: int = None,
        start: datetime.datetime = None,
        end: datetime.datetime = None,
    ) -> list[pendulum.DateTime]:
        calendar = Calendar(self.calendar_id)

        dates = calendar.business_days(
            start=pendulum.Date(2020, 1, 1),
            end=pendulum.Date(2025, 1, 1),
        )
        return [
            pendulum.instance(pendulum.DateTime.combine(date, time))
            for date in dates
            for time in self.run_times
        ]
👍 1
validation fails for schedule field in Deployment and then DeploymentCreate models
@James Sopkin Should I wait for the idea from your side or should I try to find another solution? Thanks
j

James Sopkin

09/21/2022, 1:42 PM
Hi Vadym, I did reach out to my team to ask about a dates or calendar schedule but have not hear back yet. I imagine there's an alternative solution like using lambda to trigger Prefect flows with ad-hoc scheduling, but I'd like to find out if there's a simpler solution that already exists or is in the works
Go ahead and try other ideas if you think of them
v

Vadym Dytyniak

09/21/2022, 2:22 PM
Thanks.
a

Anna Geller

09/23/2022, 4:13 PM
@Vadym Dytyniak a bit late but here is how you could schedule runs for a given date https://gist.github.com/32a0561dd3b115efebe3360574645cad
v

Vadym Dytyniak

09/23/2022, 4:21 PM
@Anna Geller looks interesting, but what about duplicates if I run the same code 2 times?
a

Anna Geller

09/23/2022, 4:27 PM
if you run it twice, it would schedule 2 runs for the same date and tbh this is a fully expected behavior
v

Vadym Dytyniak

09/24/2022, 5:53 AM
But each new deployment is new deployment_id or it depends on the version?
and what happens with old scheduled runs if you deploy new version?
a

Anna Geller

09/24/2022, 10:24 AM
#1 creating runs is independent of each other and is based on deployment ID, correct #2 scheduled runs for the old deployment are deleted and new runs are created for the new deployment
I'd encourage you to just give it a try and see how this works in practice, and if something doesn't work as you would expect, you can open a GitHub issue
🙌 1