<@ULVA73B9P> So, in Prefect 1 we would attach sche...
# ask-marvin
m
@Marvin So, in Prefect 1 we would attach schedules to flows with specific arguments (ie, "run with X arguments every day at midnight, run with Y arguments every week"). How do we do this with a Prefect 2 Deployment? Does each one have to have a unique name?
m
In Prefect 2, you can still attach schedules to flows with specific arguments using the
Deployment
class. Each deployment can have a unique name, and you can set up schedules using the
RRuleSchedule
class. However, there seems to be a bug where Prefect Cloud generates only at most 3 flow runs if you set the
count
parameter in
RRuleSchedule
to be greater than or equal to 3. For example, here's how you can schedule a flow to run every hour for 3 times:
Copy code
python
from prefect import flow
from prefect.deployments import Deployment
from prefect.server.schemas.schedules import RRuleSchedule

@flow
def foo():
    assert 1 == 1

if __name__ == "__main__":
    rrule_str = """
        DTSTART:20230908T150000
        RRULE:FREQ=HOURLY;INTERVAL=1;COUNT=3
    """
    
    Deployment.build_from_flow(
        flow=foo,
        name="foo-deployment",
        apply=True,
        schedule=RRuleSchedule(rrule=rrule_str),
    )
If you want to remove a schedule from a deployment, it's not straightforward aside from using API calls. You can set
deployment.schedule = None
and
deployment.is_schedule_active = False
to remove the scheduled runs, but the schedule itself will still be visible in the UI. Finally, if you want to run deployments for dynamic flows, you might encounter an error if the flow is not found in the given source file. This was previously supported with pickle storage in Prefect 1.x, but it seems to be an issue in Prefect 2.x. I hope this helps, even though life, the universe, and everything often doesn't make sense.
m
oof
n
i think we would say create a new deployment for each unique schedule / set of parameters
m
@Nate Marvin did get at another issue though, which is that if want to tweak something, then ya might have to delete the old one by hand.
The Prefect 1 way of doing it was perfect. You had a cron + the
parameter_defaults
argument, and you could pass a list of them.
If you wanted to reschedule one of the argument sets, you just changed it.
generating a name based on the args seems like the best stopgap (probably more likely to say "reschedule the Arguments X flow to 10PM" than vice versa)
but if we ever need to change some combination of schedule & args, it's gonna be rough.
also won't be able to retire things just by deleting them from the
.py
file