okay so I am trying to translate a prefect core fl...
# prefect-community
s
okay so I am trying to translate a prefect core flow to prefect cloud flow. I want to be able to make changes locally and have it update my cloud flow. Is this possible?
k
You will need to re-register for the most part for the changes to take effect
s
And then how do I trigger a cloud run from local after registration?
k
With Python,
Copy code
Client.create_flow_run(...)
With CLI
Copy code
prefect run --project project_name --name flow_name
will trigger a run on Cloud
s
Ah! Success.
So my ultimate goal is to have the prefect flows be a docker container, so I don't want them to register them every single time they run. But only when I run them locally, I want it to re-register. Does that make sense?
What would be the best way to do this?
k
Not super understanding, but that seems like it can be solved by a
if ___name___ == ___main___
to register right?
s
In my file there is this
Copy code
registered_flow_id = flow.register(project_name="Development")
    client.create_flow_run(flow_id=registered_flow_id)
so if I were to run it now I would force it to register every single time it runs.
k
Ah ok you can do
flow.register(build=False)
by default I guess?
Or is the issue here you don’t have an id to pass to
create_flow_run
? cuz you can use the task instead which is more flexible:
Copy code
create_flow_run.run(project_name=...,flow_name=...)
s
The latter!
k
Task docs are here
s
That's awesome
Did you mean this one? prefect.tasks.prefect.flow_run.StartFlowRun.run
k
That is also an option, but
create_flow_run
is the newer task
The inconsistency with StartFlowRun is that it changes the return depending if you set
wait=True
. wait=False returns an id and wait=True returns a state. So it was decoupled into
create_flow_run
and
wait_for_flow_run
but yes any task can be invoked as plain Python anyway with the run method
s
And there's not a secret way to have the flow detect changes right? lol
k
You can compare the
flow.serialized_hash()
. So you can try running this twice:
Copy code
prefect register -p some_flow.py
and on the second one, it will not register because no changes were made. This is because the CLI uses
flow.serialized_hash()
as an idempotency key. So if you try to register with the same idempotency key, it will just return the id of the old run
It’s a bit more complicated than that but you can see the source code of the CLI register call here
s
So it is not able to do that in-code, just via the cli?
k
Yeah that code path is only in the CLI so you’d need to replicate it or come up with your own identifier around the serialized hash