https://prefect.io logo
Title
m

Michael Kennely

10/22/2020, 9:07 PM
Hi everyone! I’m looking for guidance on the following scenario. Currently playing around with Prefect Cloud. I have my execution environment for this exercise setup to be an EC2 instance and I’m using file based storage via Github. What’s the best practice for running the
.py
file locally to test that it works as intended before pushing to GH without changing any code? From my understanding you shouldn’t have
flow.run()
in your file when using Prefect cloud, but that’s how I started off running things locally Simple hello world script for reference
import prefect

from prefect import task, Flow
from prefect.environments.storage import GitHub


@task
def hello_task():
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>("Hello world!")


hello_flow = Flow("gh_storage_flow", tasks=[hello_task])

hello_flow.storage = GitHub(
    repo="{redacted}",
    path="{redacted}",
    secrets=["{redacted}"]
)

# Basically, I want the functionality of the below line so I can run this locally via Pycharm and then push to GH, merge to main branch, register, etc, and schedule via the UI to execute in our dedicated execution environment, but when you aren't running this as a script my understanding is that you need to remove the following line
hello_flow.run()
c

Chris White

10/22/2020, 9:08 PM
Hi Michael and welcome! You should able to achieve this by putting the
.run
block within the following check:
if __name__ == "__main__":
    hello_flow.run()
this way, the run command will only run when you call
python my_file.py
but will not run when the file is loaded for use with Cloud
🤦‍♂️ 1
👍 1
m

Michael Kennely

10/22/2020, 9:10 PM
That was insanely quick, Chris! I greatly appreciate your help and I was 100% overthinking this one 😅
👍 1
c

Chris White

10/22/2020, 9:10 PM
No worries, glad I could help!