File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1+ import asyncio
2+ import time
13from dataclasses import dataclass
24
35from temporalio import activity
@@ -16,7 +18,18 @@ async def compose_greeting(input: ComposeGreetingInput) -> str:
1618 test_service = TestService ()
1719 while True :
1820 try :
19- result = test_service .get_service_result (input )
20- return result
21- except Exception :
21+ try :
22+ result = await test_service .get_service_result (input )
23+ activity .logger .info (f"Exiting activity ${ result } " )
24+ return result
25+ except Exception as e :
26+ # swallow exception since service is down
27+ activity .logger .debug ("Failed, trying again shortly" , exc_info = True )
28+
2229 activity .heartbeat ("Invoking activity" )
30+ await asyncio .sleep (1 )
31+ except asyncio .CancelledError :
32+ # activity was either cancelled or workflow was completed or worker shut down
33+ # if you need to clean up you can catch this.
34+ # Here we are just reraising the exception
35+ raise
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ def __init__(self):
33 self .try_attempts = 0
44 self .error_attempts = 5
55
6- def get_service_result (self , input ):
6+ async def get_service_result (self , input ):
77 print (
88 f"Attempt { self .try_attempts } "
99 f" of { self .error_attempts } to invoke service"
You can’t perform that action at this time.
0 commit comments