https://prefect.io logo
a

Alejandro Sanchez Losa

12/17/2021, 4:12 PM
I am trying to get the flow ID after register… is there any way ?
k

Kevin Kho

12/17/2021, 4:13 PM
You can click the details tab
upvote 1
a

Alejandro Sanchez Losa

12/17/2021, 4:14 PM
thanks !!! I mean trying do trough programming …
a

Anna Geller

12/17/2021, 4:17 PM
You can get it from the context:
Copy code
prefect.context.flow_id
a

Alejandro Sanchez Losa

12/17/2021, 4:18 PM
thanks !!! let me check
I looking for where I can call to context
a

Anna Geller

12/17/2021, 4:20 PM
in your task you can
print(prefect.context.flow_id)
a

Alejandro Sanchez Losa

12/17/2021, 4:21 PM
I though that … but does not work
a

Anna Geller

12/17/2021, 4:23 PM
you need to register the flow and run with a backend
k

Kevin Kho

12/17/2021, 4:23 PM
Oh
flow.register()
will return the id.
a

Alejandro Sanchez Losa

12/17/2021, 4:23 PM
yes but in a string human ready not to get that value
k

Kevin Kho

12/17/2021, 4:28 PM
Could you give more details to what you are trying to do?
upvote 1
a

Alejandro Sanchez Losa

12/17/2021, 4:29 PM
I need get the ID to use after in other process
as I can see the register only returns string
the idea is use the ID in other python process
I found a solution
its not elegant but it will be work for me …
k

Kevin Kho

12/17/2021, 4:35 PM
I think what you’re saying is that you register a flow, and then you can get the flow id and plug it here, but the problem is that when you re-register, the version will change and you get a new flow id so this doesn’t work right? It might be easier for you to trigger the Flow by using project name and flow name. You can do this using the create_flow_run task, which will find the flow_id for you under the hood and start the flow run. To use
create_flow_run
in a script, just import it and call the
.run()
method.
Copy code
from prefect.tasks.prefect import create_flow_run
create_flow_run.run(flow_name="flow", project_name="project")
👍 1
a

Alejandro Sanchez Losa

12/17/2021, 4:35 PM
I am trying to automate from github actions
k

Kevin Kho

12/17/2021, 4:36 PM
If you want to stick to the Client, you can use the
version_group_id
instead which doesn’t change from registration to registration
a

Alejandro Sanchez Losa

12/17/2021, 4:36 PM
umm I have to read that document
@Kevin Kho your solution working better, is more elegant !!! and easy
I apreciate
k

Kevin Kho

12/17/2021, 4:42 PM
Of course!
a

Alejandro Sanchez Losa

12/17/2021, 4:43 PM
thanks so much !!!
now i get a nice error xD
do you know why I get “No module named in /home/runner/” error ?
k

Kevin Kho

12/17/2021, 4:47 PM
I think so. When you register a Flow, Prefect puts it in “Storage”. When a Flow Run is triggered, the Flow is retrieved from Storage and executed. The default is Local Storage which is on your machine so this error is when you register with Local Storage on machine A and try to run it on machine B, which doesn’t have the file
upvote 1
😨 1
a

Anna Geller

12/17/2021, 4:47 PM
@Alejandro Sanchez Losa I think you don’t need to do any of this if the goal is to register your flow in CI. You only need to use “prefect register” CLI. Here is how I used it in CircleCI:
Copy code
version: 2
jobs:
  build:
    docker:
      - image: prefecthq/prefect:latest-python3.9
    steps:
      - checkout  # checkout source code to working directory
      - run: pip install .
      - run: prefect auth login --key $PREFECT_API_KEY
      - run: export PREFECT__CLOUD__USE_LOCAL_SECRETS=false && prefect register --project yourprojectname -p flows/ # -p sets the directory to your flows that should be registered
❤️ 1
a

Alejandro Sanchez Losa

12/17/2021, 4:49 PM
thanks so much you all guys let me read and learn
a

Anna Geller

12/17/2021, 4:49 PM
with this: you don’t need any of this I meant using Client and calling create_flow_run from script 😄 you still need to specify storage, as Kevin explained it
since you do CI already, a GitHub storage seems to be a good choice. If you need some examples, here is one for local agent
a

Alejandro Sanchez Losa

12/17/2021, 4:51 PM
maybe I need a cloud store point …
I have to read slowly that to understand
thanks so much
🙌 1
23 Views