Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Conversation

@zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Nov 12, 2024

cf flows and tasks are in fact valid prefect flows and tasks, and so this example shows how to deploy / map flows / tasks

also fixes up some typing so methods like serve and deploy are known to the IDE

@github-actions github-actions bot added example Includes an example enhancement Enhance an existing feature labels Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'something' here should probably be 'write_poems'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, an example that deploys it by pulling an image, would solve all of my problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch @alkiviadis-savvopoulos!

fixed that and also added a docker example

@zzstoatzz zzstoatzz force-pushed the example-deploy branch 3 times, most recently from 3a5b81d to 6aa3b39 Compare November 13, 2024 07:25
doesnt need to be a cf flow

wrap it in task

name
Comment on lines +53 to +98
if __name__ == "__main__":
EVERY_12_HOURS_CRON = "0 */12 * * *"
if len(sys.argv) > 1 and sys.argv[1] == "serve":
analyze_hn_articles.serve(
parameters={"n": 5},
cron=EVERY_12_HOURS_CRON,
)
elif len(sys.argv) > 1 and sys.argv[1] == "local_deploy":
analyze_hn_articles.from_source(
source=str((p := Path(__file__)).parent.resolve()),
entrypoint=f"{p.name}:analyze_hn_articles",
).deploy(
name="local-deployment",
work_pool_name="local",
cron=EVERY_12_HOURS_CRON,
)
elif len(sys.argv) > 1 and sys.argv[1] == "docker_deploy":
repo = GitRepository(
url="https://github.com/PrefectHQ/controlflow.git",
branch="main",
credentials=None, # replace with `dict(username="", access_token="")` for private repos
)
analyze_hn_articles.from_source(
source=repo,
entrypoint="examples/read_hn.py:analyze_articles",
).deploy(
name="docker-deployment",
# image=DockerImage( # uncomment and replace with your own image if desired
# name="zzstoatzz/cf-read-hn",
# tag="latest",
# dockerfile=str(Path(__file__).parent.resolve() / "read-hn.Dockerfile"),
# ),
work_pool_name="docker-work", # uv pip install -U prefect-docker prefect worker start --pool docker-work --type docker
cron=EVERY_12_HOURS_CRON,
parameters={"n": 5},
job_variables={
"env": {"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY")},
"image": "zzstoatzz/cf-read-hn:latest", # publicly available image on dockerhub
},
build=False,
push=False,
)
else:
print(f"just running the code\n\n\n\n\n\n")
briefs = analyze_hn_articles(5) # type: ignore
TypeAdapter(list[HNArticleSummary]).validate_python(briefs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement Enhance an existing feature example Includes an example

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants