https://prefect.io logo
g

Gustavo Zuniga Goni

09/12/2023, 11:04 PM
Hello, I have this simple code and I am running the following instructions to deploy it:
Copy code
prefect deployment build flujo_llamaOtro.py:flujo_llamaOtro --name flujo_llamaOtro
prefect deployment apply flujo_llamaOtro-deployment.yaml
But I want it to run immediately after I deploy it and not have to enter these commands manually: prefect agent start -q ‘default’
Copy code
prefect deployment run 'flujo_llamaOtro/flujo_llamaOtro'
Can somebody help me?
Copy code
from prefect import flow, task,
from prefect.deployments import run_deployment

@task
def tarea_a(valor: int):
    valor = valor +700
    run_deployment("flujo_quesellama/flujo_quesellama")
    return valor

@task
def tarea_b(valor: int):
    valor = valor + 1
    return valor

@flow(name="flujo_llamaOtro",description="Este Flujo sera el que llama a otro que se ejecute",log_prints=True)
def flujo_llamaOtro(valor: int = 111 ):
    rtarea_a = tarea_a(valor)
    print(rtarea_a)
    rtarea_b = tarea_b(rtarea_a)
    print(rtarea_b)
n

Nate

09/12/2023, 11:16 PM
hey @Gustavo Zuniga Goni - how's this?
Copy code
from prefect import flow, task,
from prefect.deployments import run_deployment

@task
def tarea_a(valor: int):
    valor = valor +700
    run_deployment("flujo_quesellama/flujo_quesellama")
    return valor

@task
def tarea_b(valor: int):
    valor = valor + 1
    return valor

@flow(name="flujo_llamaOtro",description="Este Flujo sera el que llama a otro que se ejecute",log_prints=True)
def flujo_llamaOtro(valor: int = 111 ):
    rtarea_a = tarea_a(valor)
    print(rtarea_a)
    rtarea_b = tarea_b(rtarea_a)
    print(rtarea_b)

if __name__ == "__main__":
    flujo_llamaOtro.serve(name=__file__)
Copy code
if __name__ == "__main__":
    flujo_llamaOtro.serve(name=__file__)
when you do
python my_flow.py
- the flow's
serve
command will create a deployment and it will be ready to trigger via CLI, UI, or API otherwise
g

Gustavo Zuniga Goni

09/12/2023, 11:24 PM
What you tell me is correct. But what I don’t know is how to make it run immediately. Isn’t there a code instruction that I can put in the python code?
n

Nate

09/12/2023, 11:28 PM
well if you just want it to run immediately, you can just run the python function 🙂
Copy code
if __name__ == "__main__":
    flujo_llamaOtro()
g

Gustavo Zuniga Goni

09/12/2023, 11:36 PM
Si lo hago de esta forma tengo problemas al ejecutar un flujo que se encuentra desplegado por medio de la tarea_a For that reason I must also deploy this flow packages/prefect/client/base.py”, line 138, in raise_for_status raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.cause prefect.exceptions.PrefectHTTPStatusError: Client error ‘404 Not Found’ for url ‘http://ephemeral-prefect/api/deployments/name/flujo_quesellama/flujo_quesellama’ Response: {‘detail’: ‘Deployment not found’} For more information check: https://httpstatuses.com/404 The above exception was the direct cause of the following exception:
👍 1