If I use Prefect Cloud to schedule flows and have ...
# ask-community
j
If I use Prefect Cloud to schedule flows and have a Local agent for the execution. Do I need use .run() while registering the flow and keep this terminal open?
y
Hi Jelle! You don’t need to use
.run()
if you registered the flow on Prefect Cloud. You can click “quick run” on Cloud dashboard and your flow will be running, assuming you have your prefect agent set up.
👍 1
Are you familiar with the concept of Prefect Agent?
This is Prefect Architecture Overview - fyi
j
When I manually run it though the dashboard the tasks don't execute. I just restarted my local Agent and it ran the overdue tasks. Maybe there's an issue there.
y
Yes exactly! You got it right. The flow will only be running when the agent is set up and running.
j
Quick other question if you don't mind, if I have my local agent executing the tasks, what is the root folder at execution time? I have a few utility files containing functions that I want to import. Currently I'm getting a ModuleNotFoundError.
y
Once the agent is not running, Prefect cloud will not be able to control your computer and run the code. Agent is the bridge between the cloud and the “execution layer” (e.g. your local computer)
j
The weird thing was that the Agent was running, but maybe it had an issue which needed resetting.
y
If i understand the question correctly, you can just import in the normal python way. Relative path to your
flow.py
file
j
When I execute the flow using .run() it works. Through the cloud I get this error:
y
interesting! just gathering more information as I don’t have immediate answer to this: Do you run your prefect agent under same root folder as your
flow.py
?
If not, it’s worth a try to turn down the Agent and run again in the file folder
j
i run the agent from /vstPrefect, the flows are in /vstPrefect/dags
I'll try that
I think that seems to do the trick! The agent needs to run from the exact same location.
y
Yeah! the dev experience can be better - i also ran into this before.
Now you can try out the schedule feature in the UI, it’s fun. Also you can use “automation” to send slack message or email, it’s also quite nice
j
Thanks!
k
Yep the agent working dir is the same location it is spun up from. This is not convenient if you have one agent for multiple flows, so in that case, you can use the
LocalRun(working_dir="...")
to change the working directory.