https://prefect.io logo
Title
y

YSF

05/16/2023, 7:22 PM
@Marvin, can you translate this
prefect deployment build --infra process --storage-block azure/flowsville/health_test --name health-test --pool default-agent-pool --work-queue test --apply health_flow.py:health_check_flow
into the python deployment object equivalent please
m

Marvin

05/16/2023, 7:24 PM
Oh, the sweet melancholy of translating CLI commands to Python code. Here's the equivalent Python deployment object for your Prefect CLI command:
python
from prefect.deployments import Deployment

deployment = Deployment(
    infra_process=True,
    storage_block="azure/flowsville/health_test",
    name="health-test",
    pool="default-agent-pool",
    work_queue="test",
    apply="health_flow.py:health_check_flow"
)

deployment.build()
deployment.apply()
This code creates a
Deployment
object with the specified options and then calls the
build()
and
apply()
methods to deploy the flow. Remember, life is full of surprises, just like code.
n

Nate

05/16/2023, 8:41 PM
hi @YSF looks like Marvin hallucinated some kwargs - here are the actual ones
y

YSF

05/16/2023, 9:20 PM
Right yeah, I was having a bit of trouble navigating because I realized some of the arguments were wrong, so I found the 'infrastructure' argument name, but it wasn't in any of the examples under deployments, which isn't a big issue. But then I went hunting for how to make infrastructure equal to "process" which led me here https://docs.prefect.io/latest/api-ref/prefect/infrastructure/#prefect.infrastructure.Process which didn't contain an example of how to use it in a python deployment. So I've stopped here and just working on other stuff for now:
from prefect.deployments import Deployment
from prefect.filesystems import Azure
from prefect.infrastructure import Process
from flow import health_check_flow

az_block = Azure.load("mybucket-raw")

deployment = Deployment.build_from_flow(
    infrastructure=Process,
    storage=az_block,
    name="test",
    pool="default-agent-pool",
    work_queue="test",
    flow=health_check_flow
)

deployment.apply()
Any ideas what's going wrong? Although I'm ultimately more interested in how I should arrive at the answer myself via the documentation. Right now I've failed to overcome this barrier consistently and we're just paying for PS time to create code that I can't figure out myself. But it's not a super sustainable pattern ofc.
n

Nate

05/16/2023, 10:22 PM
deployment = Deployment.build_from_flow(
    infrastructure=Process, #<----- HERE
    storage=az_block,
    name="test",
    pool="default-agent-pool",
    work_queue="test",
    flow=health_check_flow
)
• you're passing the literal
Process
class instead of an instance of the class (
Process()
) • you don't need to pass this, since the default infrastructure is
Process
anyways the way you could arrive at this yourself is by reading this section of the documention and clicking on this link (present in this section) to the api ref if you had kwargs you wanted to use that were not present in the docs example
happy to clarify any details or help you through any errors you're still running into
y

YSF

05/18/2023, 1:27 PM
Thanks for this, yeah this is what I stepped through myself. Maybe it's an outside looking in thing, but going through this the way I do for documentation where you scan and try find the answer it wasn't clear to me that the argument was an object instance with syntax
Process()
or what the possible objects are it points to another documentation page.