Skip to content
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

Refactor: Correct polling infrequent/periodic_sequence usecase #125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion polling/infrequent/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ComposeGreetingInput:

@activity.defn
async def compose_greeting(input: ComposeGreetingInput) -> str:
test_service = TestService()
attempt = activity.info().attempt - 1
test_service = TestService(attempt=attempt)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Seems this was written with a bug.

I think a cleaner approach would be to make this activity a method (and call via execute_activity_method from workflow) and instantiate the TestService as class state.

Also, I think frequent polling is affected by this same test service issue.

# If this raises an exception because it's not done yet, the activity will
# continually be scheduled for retry
return await test_service.get_service_result(input)
6 changes: 3 additions & 3 deletions polling/test_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TestService:
def __init__(self):
self.try_attempts = 0
self.error_attempts = 5
def __init__(self, attempt=0, error_attempts=5):
self.try_attempts = attempt
self.error_attempts = error_attempts

async def get_service_result(self, input):
print(
Expand Down