-
Notifications
You must be signed in to change notification settings - Fork 115
Update SDK and add hello world sample #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Hello World | ||
|
|
||
| This sample shows a basic workflow that calls a basic activity, a worker that runs the workflow/activity, and a client | ||
| that invokes the workflow. | ||
|
|
||
| To run, first see [README.md](../README.md) for prerequisites. Then, run the following from this directory: | ||
|
|
||
| poetry run python hello_world.py | ||
|
|
||
| The result will be: | ||
|
|
||
| Result: Hello, Temporal! |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import asyncio | ||
| import logging | ||
| from datetime import timedelta | ||
|
|
||
| from temporalio import activity, workflow | ||
| from temporalio.client import Client | ||
| from temporalio.worker import Worker | ||
|
|
||
|
|
||
| # Basic activity that logs and does string concatenation | ||
| @activity.defn | ||
| async def say_hello_activity(name: str) -> str: | ||
| activity.logger.info("Running activity with parameter %s" % name) | ||
| return f"Hello, {name}!" | ||
|
|
||
|
|
||
| # Basic workflow that logs and invokes an activity | ||
| @workflow.defn | ||
| class SayHelloWorkflow: | ||
| @workflow.run | ||
| async def run(self, name: str) -> str: | ||
| workflow.logger.info("Running workflow with parameter %s" % name) | ||
| return await workflow.execute_activity( | ||
| say_hello_activity, name, start_to_close_timeout=timedelta(seconds=10) | ||
| ) | ||
|
|
||
|
|
||
| async def main(): | ||
| # Uncomment the line below to see logging | ||
| # logging.basicConfig(level=logging.INFO) | ||
|
|
||
| # Start client | ||
| client = await Client.connect("http://localhost:7233") | ||
|
|
||
| # Run a worker for the workflow | ||
| async with Worker( | ||
| client, | ||
| task_queue="my-task-queue", | ||
| workflows=[SayHelloWorkflow], | ||
| activities=[say_hello_activity], | ||
| ): | ||
|
|
||
| # While the worker is running, use the client to run the workflow and | ||
| # print out its result. Note, in many production setups, the client | ||
| # would be in a completely separate process from the worker. | ||
| result = await client.execute_workflow( | ||
| SayHelloWorkflow.run, | ||
| "Temporal", | ||
| id="my-workflow-id", | ||
| task_queue="my-task-queue", | ||
| ) | ||
| print(f"Result: {result}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just remove this no need for it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has some polyglot value, but later as the sample count grows, I may rename it to "activity-only worker" or something.