I am trying to get the flow ID after register… is ...
# ask-community
a
I am trying to get the flow ID after register… is there any way ?
k
You can click the details tab
upvote 1
a
thanks !!! I mean trying do trough programming …
a
You can get it from the context:
Copy code
prefect.context.flow_id
a
thanks !!! let me check
I looking for where I can call to context
a
in your task you can
print(prefect.context.flow_id)
a
I though that … but does not work
a
you need to register the flow and run with a backend
k
Oh
flow.register()
will return the id.
a
yes but in a string human ready not to get that value
k
Could you give more details to what you are trying to do?
upvote 1
a
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
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
I am trying to automate from github actions
k
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
umm I have to read that document
@Kevin Kho your solution working better, is more elegant !!! and easy
I apreciate
k
Of course!
a
thanks so much !!!
now i get a nice error xD
do you know why I get “No module named in /home/runner/” error ?
k
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
@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
thanks so much you all guys let me read and learn
a
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
maybe I need a cloud store point …
I have to read slowly that to understand
thanks so much
🙌 1