<@ULVA73B9P> I have a piece of code that looks lik...
# ask-marvin
t
@Marvin I have a piece of code that looks like this:
Copy code
result = run_deployment(
    timeout=0,
    name="submit-tasks/local-deploy",
    scheduled_time=(datetime.now() + timedelta(minutes=2)),
    parameters={
        "a": randint(1, 5),
        "b": randint(1, 5),
        "c": randint(1, 5),
    },
    as_subflow=False,
)
It should reschedule the flow to run 2 minutes later, but the newly created flow executes immediately. Why is that?
1
m
It appears that specifying a
scheduled_time
directly in
run_deployment
may not work the way you expect due to the intricacies of the Prefect Scheduler and its scheduling mechanisms. Here are some critical points from the documentation: 1. Scheduler Service: - The Scheduler service in Prefect works on a loop, revisiting deployments per its schedule. It evaluates each deployment's schedules and creates new runs appropriately, usually up to three runs in advance. - Recently modified deployments are checked more frequently, but there is still a delay. 2. Running Deployments: - Immediate execution might be the default behavior if the schedule isn't properly accounted for or if there is a timing mismatch with the Scheduler service loop. To ensure the flow runs at the desired time, consider using a dedicated scheduling mechanism within the deployment configuration or adjust the deployment's schedule more explicitly. Here's a documentation link that might provide more insight: Prefect Schedules Is that suitably depressing?
c
@Tate Wilks it's possible that the problem is a timezone issue; perhaps try the following instead:
Copy code
import pendulum

...
scheduled_time=pendulum.now("utc").add(minutes=2)
t
@Chris White that seems to have resolved it, thank you for suggesting that!
c
awesome, anytime!