Question: is there a way to stop a local agent but...
# best-practices
d
Question: is there a way to stop a local agent but waiting until any running flows are completed?
j
following
k
How can we signal an agent to stop polling for new work (and to shut down when current jobs are done)? I'm looking to start a new agent on the same queues, but not lose the flow runs on the existing agent.
d
I emailed support and got this response
Copy code
Thanks for reaching out to us. There isn't a specific command to stop an agent once it's been started beyond interrupting the process manual or killing the process that's running it. That said it's relatively straightforward to check for running flows via the CLI with this command prefect flow-run ls --state RUNNING, this is also doable from the API so it should theoretically be possible to write a script that kills the agent process if there are no currently running flow runs but to my knowledge there's nothing built natively into the agent process to do this.
j
Can y’all elaborate on the underlying motivation for your interest in such a feature?
d
We have containers running local agents and want to be able to update them without killing a running flow.
k
Exactly - we want the existing agents to "drain". Finish any existing work, and then exit. Say we start a second agent in parallel, that touches the same queues. The second agent has new code, and we want all future flow runs to go to that agent. But currently running Flow runs are acceptable to finish; we don't want to KILL that agent, and lose the work.
j
bump