Skip to content

fix missing sleep to properly poll inside activity #122

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 7 commits into from
Jun 11, 2024
Merged
Changes from 2 commits
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
15 changes: 14 additions & 1 deletion polling/frequent/activities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
import time
from dataclasses import dataclass

from temporalio import activity
Expand All @@ -17,6 +19,17 @@ async def compose_greeting(input: ComposeGreetingInput) -> str:
while True:
try:
result = test_service.get_service_result(input)
activity.logger.info(f"Exiting activity ${result}")
return result
except Exception:
except Exception as e:
# swallow exception since service is down
activity.logger.error(e)

try:
activity.heartbeat("Invoking activity")
except asyncio.CancelledError as exception:
# activity was either cancelled or workflow was completed or worker shut down
# if you need to clean up you can catch this. Here we are just reraising exception
raise

await asyncio.sleep(1)