This repository was archived by the owner on Aug 22, 2025. It is now read-only.
Open
Conversation
examples/deploy.py
Outdated
There was a problem hiding this comment.
'something' here should probably be 'write_poems'.
There was a problem hiding this comment.
Also, an example that deploys it by pulling an image, would solve all of my problems.
Collaborator
Author
There was a problem hiding this comment.
nice catch @alkiviadis-savvopoulos!
fixed that and also added a docker example
better example updates fix kwargs
3a5b81d to
6aa3b39
Compare
6aa3b39 to
ce25892
Compare
zzstoatzz
commented
Jan 13, 2025
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
serveanddeployare known to the IDE