-
Notifications
You must be signed in to change notification settings - Fork 70
Convert hello activities to sync #173
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
GSmithApps
merged 17 commits into
temporalio:main
from
GSmithApps:convert-activities-to-sync
Jun 9, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
db87dcc
converting async activities to sync: first chunk
GSmithApps 31c7d41
converting async activities to sync: second chunk
GSmithApps c5b9565
converting async activities to sync: third chunk
GSmithApps e3741e0
fixed small async straggler
GSmithApps b367478
converting async activities to sync: async completion
GSmithApps 45d78a0
reviewed my own code
GSmithApps b191546
fix lints
GSmithApps 2299e65
fixed more lints
GSmithApps eb0f5b7
responded to review comments
GSmithApps 7b2035e
Merge branch 'remote-main' into convert-activities-to-sync
GSmithApps 015a182
fixed mistake on not awaiting a future
GSmithApps 2f5a3df
Merge branch 'temporalio:main' into convert-activities-to-sync
GSmithApps 394daff
fixed tests
GSmithApps ce1c741
revert async activity completion changes
GSmithApps 46b8a62
added code owners
GSmithApps 67dd2cc
deleted code owners
GSmithApps e794944
Merge branch 'temp-main' into convert-activities-to-sync
GSmithApps 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import asyncio | ||
from dataclasses import dataclass | ||
from datetime import timedelta | ||
|
||
from temporalio import activity, workflow | ||
from temporalio.client import Client | ||
from temporalio.worker import Worker | ||
|
||
|
||
# While we could use multiple parameters in the activity, Temporal strongly | ||
# encourages using a single dataclass instead which can have fields added to it | ||
# in a backwards-compatible way. | ||
@dataclass | ||
class ComposeGreetingInput: | ||
greeting: str | ||
name: str | ||
|
||
|
||
# Basic activity that logs and does string concatenation | ||
@activity.defn | ||
async def compose_greeting(input: ComposeGreetingInput) -> str: | ||
activity.logger.info("Running activity with parameter %s" % input) | ||
return f"{input.greeting}, {input.name}!" | ||
|
||
|
||
# Basic workflow that logs and invokes an activity | ||
@workflow.defn | ||
class GreetingWorkflow: | ||
@workflow.run | ||
async def run(self, name: str) -> str: | ||
workflow.logger.info("Running workflow with parameter %s" % name) | ||
return await workflow.execute_activity( | ||
compose_greeting, | ||
ComposeGreetingInput("Hello", name), | ||
start_to_close_timeout=timedelta(seconds=10), | ||
) | ||
|
||
|
||
async def main(): | ||
# Uncomment the lines below to see logging output | ||
# import logging | ||
# logging.basicConfig(level=logging.INFO) | ||
|
||
# Start client | ||
client = await Client.connect("localhost:7233") | ||
|
||
# Run a worker for the workflow | ||
async with Worker( | ||
client, | ||
task_queue="hello-activity-task-queue", | ||
workflows=[GreetingWorkflow], | ||
activities=[compose_greeting], | ||
# If the worker is only running async activities, you don't need | ||
# to supply an activity executor because they run in | ||
# the worker's event loop. | ||
): | ||
|
||
# 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( | ||
GreetingWorkflow.run, | ||
"World", | ||
id="hello-activity-workflow-id", | ||
task_queue="hello-activity-task-queue", | ||
) | ||
print(f"Result: {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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
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
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
Oops, something went wrong.
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 think all of these samples are going to give warnings of:
Can you confirm you are getting these warnings? Can you up the value passed here to 100?
Uh oh!
There was an error while loading. Please reload this page.
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 don't think i got those warnings. (Chad and I subsequently discussed off-PR)
Or I can just go ahead and up it to 100 anyway
Uh oh!
There was an error while loading. Please reload this page.
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.
Interesting, I wonder why they aren't showing, we may have to investigate, but lack of warnings appearing is not a blocker for this issue of course