https://prefect.io logo
Title
e

Ethienne Marcelin

02/03/2023, 4:02 PM
Hi all ๐Ÿ˜„ I have little problem, prefect version 2.7.8 a flow is defined in test.py which content is very simple:
from prefect import flow

@flow
def myflow(x: int):
    return x ** x
I want to run this flow with a deployment so i do the following:
from prefect.deployments import Deployment, run_deployment
from test import myflow

deployment = Deployment.build_from_flow(flow=myflow, name="test", version=1)
deployment_uuid = deployment.apply()
output = run_deployment(name=f"{deployment.flow_name}/{deployment.name}", parameters={"x": 3})
Everything works fine, but the program never returns ๐Ÿ˜ข it's stuck on the "run_deployment" When I do
prefect flow-run ls
I see that my flow-run was created but is stuck in "scheduled" state. I have the same problem if I run this code within a "if name == main" block, if I specify a work queue name, or add a schedule time in the future. Do you have any idea ? Thanks in advance for your precious help ๐Ÿ’“
โœ… 1
n

Nate

02/03/2023, 4:26 PM
Hi @Ethienne Marcelin are you running an agent?
e

Ethienne Marcelin

02/03/2023, 4:27 PM
Yes I tried with an agent, and specified the work queue name I started the agent with prefect agent star -q test
n

Nate

02/03/2023, 4:29 PM
ahh, try passing
work_queue_name="test"
to your
build_from_flow
call
e

Ethienne Marcelin

02/03/2023, 4:30 PM
Thatโ€™s what i did but it had no effect :(
n

Nate

02/03/2023, 4:31 PM
hmm could you try doing a CLI command just as a sanity check?
prefect deployment build test.py:myflow -n test -q test --apply
e

Ethienne Marcelin

02/03/2023, 4:35 PM
Yes of course ! Iโ€™m in the subway so iโ€™ll try when iโ€™m back home
๐Ÿƒ 2
n

Nate

02/03/2023, 4:36 PM
sounds good ๐Ÿ™‚
e

Ethienne Marcelin

02/03/2023, 5:35 PM
By doing the command provided it works, but I wonder what i'm missing in my code๐Ÿค”
okay, i need to start the agent ๐Ÿคฆ sorry
thanks @Nate ๐Ÿ’™
n

Nate

02/03/2023, 5:38 PM
sure thing ๐Ÿ˜„ that's why we're here
glad you figured it out
e

Ethienne Marcelin

02/03/2023, 5:48 PM
Is it possible to start the agent programatically ? Or i must use the CLI ?
n

Nate

02/03/2023, 6:10 PM
there's not a python interface for running agents in prefect 2, I'd recommend using the CLI to start the agent process what's your use case that you'd want do it programmatically?
e

Ethienne Marcelin

02/03/2023, 6:13 PM
i don't want to manage the agent "by hand" with the cli At then end of my program, how do I kill the agent without hitting ctrl-c ? Should I use prefect.infrastructure ?
n

Nate

02/03/2023, 6:23 PM
prefect infrastructure is a way of telling your agent how it should actually execute your flow run, if you don't specify infrastructure for a deployment, your agent will assume that it should create a local process (where the agent is running) for your flow run usually agents are meant to be a long-lived process, typically people will start an agent on a VM or a kubernetes pod using the helm chart and just keep it running so it can pick up future flow runs so I guess the short answer is that you would need to manually kill the agent if you only wanted it to exist for the duration of a flow run but its totally valid to just not create a deployment and just run your flow when you want, the runs will still show up in your UI (no agent required) - its just that when you want to attach a schedule or alter flow run parameters from the UI, you'll need a deployment and an agent that can pick up its flow runs
e

Ethienne Marcelin

02/03/2023, 6:26 PM
Ok I see I misunderstood agents ! You're the best Nate thanks :))
n

Nate

02/03/2023, 6:26 PM
sure thing! lmk if any other questions come up