How does the Prefect agent get notified of new flo...
# ask-community
m
How does the Prefect agent get notified of new flows? I am running the agent in a Docker container and it is active and connected to apollo. Also I mapped the .prefect directory as a volume. But the Agent does not pick up new flows (when clicking run in the UI). When I run
prefect agent start
in my main Docker container the process picks up the flows
👀 1
n
Hi @Matthias! Would you mind trying:
export PREFECT__CLOUD__API={docker.url}:{port}
? Replacing the stuff in curly braces with your exposed docker setup?
(probably localhost and whatever port you've exposed for apollo)
Oh and then restarting the agent after, sorry!
m
Hi @nicholas ! Thanks, but that did not do the trick
n
Ah I misunderstood, sorry. The way the agent works is it polls the server every ~10 seconds. So the agent in the container needs to have access to your apollo server (be default this is localhost:4200 for Prefect Server), and it needs to be correctly pointed wherever that is.
Oh! Have you run
prefect backend server
?
m
Everything is set up like that. I even tried to curl the graphql out of the agent Container and I got the results. Still, it does not act on available flows. Really strange. I‘ll investigate further. Is there a way to get logs from the agent?
n
Strange indeed. You can start the agent with the
--verbose
flag to get some more info from it
One other thing to investigate: what are the labels you're using on your registered flows and does your agent have labels to match?
m
Huh, I assume it is related to the label. The registration seems to default to the hostname, and by default includes this as a label when running the agent. When I run the agent in a different containter, the hostname is different and there are no matching labels
I’ll dig into this. It should be fine to run the agent like this
prefect agent start --label prod
and to register the flow like this
flow.register(labels=["prod"])
, to match right?
n
That would make sense since it sounds like you're running the Local Agent. One thing to note there is that the agent will need access to the flows that you're registering, probably by specifying storage of some sort
Yup that'll match the labels! But the agent, since it's in a container, will need to have access to wherever your flow lives, whether that's a docker image, gcs, etc
m
yes, i am making sure of that
Thanks!
n
Great! Let me know if you get it solved 🙂
m
Would it throw an error, if the agent gets a flow from apollo, but does not find it in storage?
n
I think it will
I believe the flow runner will fail to start
m
so the setup with the label as I described above did not work yet.
Still strange 😄
n
Hm, are you able to send a minimum repro of your flow?
m
I’ll try to create something. Nothing public right now :/
n
Something that was brought to my attention was that if you're using LocalStorage for your flows, even if you're making the actual filesystem available to your agent container, there will be extra labels added to the flow by default. So when you're starting your agent, the agent will need to have all the labels your flow has, something like this:
prefect agent start --label prod -l HOSTNAME -l etc
m
That was it! Thanks so much 🙂
😄 1