https://prefect.io logo
Title
c

Christian Petersen

09/15/2022, 7:56 AM
Hi all πŸ™‚ I am experimenting with a setup running the prefect-server in kubernetes, and having another container run an agent. But before running this agent, using
prefect agent start -q 'foo'
for example, I’d like to create and apply deployments using the
Deployment.build_from_flow
syntax described here https://docs.prefect.io/concepts/deployments/#create-a-deployment-from-a-python-object . Then I want this python script to run before I start the agent…
from prefect.deployments import Deployment
from flows.deployments.example_script import flow_name


deployment = Deployment.build_from_flow(
    flow=flow_name,
    name="Test",
    work_queue_name="test",
)

deployment.apply()
I’ve tried running it standalone and in Docker but I get a Attribute Error
module 'flows.deployments.example_script.flow_name' has no attribute 'name'
If I use
setattr(flow_name, 'name', 'something)'
before the definition of
deployment
then I don’t get this exact error but this
ValueError: Could not determine flow's file location.
I’m unsure of where to begin and would love any sort of help
βœ… 1
m

Mathijs Carlu

09/15/2022, 8:27 AM
What does your example_script look like?
c

Christian Petersen

09/15/2022, 8:32 AM
I import a bunch of functions from other project modules and encapsule some in
@task()
decorators, and use these in one function encapsulated by
@flow()
I forgot to mention I am simply calling the pre-agent startup script with
python pre-start.py
m

Mathijs Carlu

09/15/2022, 9:02 AM
I don't know what you're doing wrong, since you're not providing much evidence you do everything right. This is working for me. File structure is this:
.
β”œβ”€β”€ deploy.py
└── flows
β”œβ”€β”€ __init__.py
└── deployments
β”œβ”€β”€ __init__.py
└── example_script.py
deploy.py contains the same code as you gave above, example_script looks like this:
from prefect import task, flow
@task
def function_one():
pass
@task
def function_two():
pass
@flow
def flow_name():
function_one()
function_two()
Also, if you're going to run your agent in kubernetes, you might want to use storage, since the agent needs some way to access the flow code
c

Christian Petersen

09/15/2022, 9:32 AM
Hi @Mathijs Carlu, thanks for your help, I’ve found the problem, I was passing the module instead of the function, stupid me. I’ve been trying to debug this for longer than I want to admit πŸ₯΅
πŸ‘ 2