Hello guys, I have a weird behaviour while using p...
# ask-community
a
Hello guys, I have a weird behaviour while using prefect Orion deployments with the UI, I have this deployment file:
Copy code
import pandas as pd
from prefect.deployments import DeploymentSpec
from prefect.orion.schemas.schedules import IntervalSchedule

from pred.predict import predict_flow

DeploymentSpec(
    flow=predict_flow,
    name="Prediction"
)
I create the deployment without a problem and I can see it in the UI. I also can run it successfully from CLI using:
Copy code
prefect deployment execute 'Prediction flow/Prediction'
But When I try to run it using the “Quick Run” in the UI, a “Scheduled” task is created and is never run. I can see it in the lateness graph. one task didn’t run for over an hour during my lunch break. Same happens if I add a schedule to the deployment. any ideas why that happens or how to fix it?
a
Just yesterday, there was a new Orion release which makes the process way easier thanks to FlowRunners. Can you upgrade your Orion version (
pip install -U "prefect>=2.0a6"
) and try e.g. this tutorial? It shows how deployment can be run on an agent. There is also this brand new concept documentation of Deployments that can help understand how this works.
to explain it a bit more: “prefect deployment execute” creates a local flow run, which is equivalent to running your script with “python yourscript.py”. To test whether your deployment can run on schedule, you can try “prefect deployment run” instead. But to run deployment on schedule, an orion instance must be running with an agent (by default Prefect starts an agent automatically when you run
prefect orion start
)
a
Thank you Anna! Upgrading prefect to “2.0a6” solved the “Quick Run” problem. I’m testing it now with a schedule. I’ll post again if there is still a problem
👍 1
@Anna Geller I have a question if possible. I’ve read all docs and have been testing this for a while now. Here https://orion-docs.prefect.io/concepts/deployments/#creating-deployments-with-the-cli the docs state:
Copy code
Scheduled flow runs will not be created unless the scheduler is running. Scheduled flow runs will not run unless an agent is running. The scheduler and agent are included in the services started by "prefect orion start".
I have a couple of questions here: • Does that mean a scheduled deployment will not work at all if the deployment was created before running other stateful Orion services? • Is there a way to schedule and run a deployment later after its creation if
prefect orion start
was not run first? • What if the Orion services need to restart for some reason, would that mean the scheduled tasks are interrupted and the scheduled flow needs to be updated/re-created? Thanks
a
It only means that Orion can’t schedule flow runs specified in your Deployment unless the Orion instance with scheduler and agent services is started. This means that you can create deployments at any time, but in order for Orion to schedule flow runs, the Orion instance must be running. When you create deployments, you only send metadata to Orion’s backend so that it knows what flow to run, how to run it (parameters), when to run it (schedule) and where to run it (flow runner). The actual runs are handled by the services you spawn when you start Orion. Regarding the last question, I think this is what the late runs service is for, your scheduled runs should be picked up by the scheduler and submitted to the agent once you restarted Orion.
a
By “stateful Orion services” I mean running
prefect orion start
The reason I’m asking is that when I try to create a deployment without running
prefect orion start
first, The flow runs are still created but they never run as you see from the appended screenshot. The only way I got them to work is by making sure
prefect orion start
runs first before creating any deployment.
a
Gotcha, that seems to make sense though, right? because before you run “prefect orion start”, there is no agent to pick up your flow run, so UI is correct to display those as scheduled and basically waiting. Or would you expect a different behavior?
a
It’s ok to have this behaviour I guess, my question then would be: Is there a way to make an agent pick up those flow runs later?
a
I think once you would deploy your flows to “production”, then it shouldn’t be an issue since the agent will be up at all times, and I think it’s possible that you could even have two agents so that a separate agent service can pick up flow runs if the main agent service is down somehow. And my understanding is that the
MarkLateRuns
 service places such flow runs (not picked up by an agent at the time they were schedule to run) in a 
Late
 state so that they can be picked up for execution later.
a
Maybe this
MarkLateRuns
doesn’t run efficiently as I expect then. I also can’t see a way in documentation on how can we make sure that such service is up and running as expected, or see the flows is detected. I’m not sure I fully understand everything yet but I guess I have enough information to keep me going. Thanks!
👍 1