https://prefect.io logo
Title
g

Gregory Hunt

05/18/2023, 12:25 PM
Where does the code the
if __name__ == "__main__":
block on code run. Does it run on the Agent? I am working on setting up a streaming flow with GCP Cloudrun jobs for the worker pool and am curious sync this part of the flow is continuous?
n

Nate

05/18/2023, 2:38 PM
can you explain what you mean by this?
Where does the code the
if __name__ == "__main__":
block on code run
if you mean you have something like this that you've created a deployment from
@flow
def my_flow():
   pass

if __name__ == "__main__":
   my_flow()
in your local flow file, that
if __name__ == "__main__":
block doesn't actually run when your agent pulls -> submits your deployment flow run the prefect engine will call your flow with the parameters (default, or the ones you provided), as the
flow
-decorated function was defined in your local flow file when you created the deployment from it - does that make sense?
g

Gregory Hunt

05/18/2023, 2:39 PM
So in my case instead of my_flow()
I will have a pubsub subscriber
which will call my_flow everytime it gets a message
So where does that code get executed?
where is the while loop executed, if auth was needed which service would need that auth?
n

Nate

05/18/2023, 2:54 PM
the while loop pattern would work if you're running the flow as a script on some machine, but it doesn't work directly if you've created a deployment and are deferring the submission of the flow run to the Prefect engine, since the prefect engine will call your entrypoint flow directly with the appropriate parameters (which means you can't directly add logic like the while loop on top of the deployment entrypoint) is it possible in your setup to have your publisher post directly to
create_flow_run_from_deployment
(via run_deployment)? that way you could let the prefect API act as the listener, triggering a new flow run each time some event comes through instead of having a while loop