Hi. Does RRuleSchedule support something like? I w...
# prefect-community
v
Hi. Does RRuleSchedule support something like? I was able to deploy the flow, but don't see any scheduled flow runs.
Copy code
RDATE:20220920T200000Z,20220921T133000Z
UI says: 'Every year' schedule:
j
hi Vadym, check out the docs here. The example provided is this
Copy code
schedule:
  rrule: 'FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20240730T040000Z'
Could you clarify what you are trying to do with the rrule schedule?
v
Sure. I used DatesClock to run flows using custom calendar and now I am looking for the solution in Prefect 2.
j
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
Thanks a lot! I was trying to implement custom schedule, but pydantic validation does not allow custom model fields.
Copy code
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
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
Thanks.
a
@Vadym Dytyniak a bit late but here is how you could schedule runs for a given date https://gist.github.com/32a0561dd3b115efebe3360574645cad
v
@Anna Geller looks interesting, but what about duplicates if I run the same code 2 times?
a
if you run it twice, it would schedule 2 runs for the same date and tbh this is a fully expected behavior
v
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
#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