File tree 4 files changed +18
-16
lines changed
4 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,12 @@ class ComposeGreetingInput:
11
11
name : str
12
12
13
13
14
- @activity .defn
15
- async def compose_greeting (input : ComposeGreetingInput ) -> str :
16
- attempt = activity .info ().attempt - 1
17
- test_service = TestService (attempt = attempt )
18
- # If this raises an exception because it's not done yet, the activity will
19
- # continually be scheduled for retry
20
- return await test_service .get_service_result (input )
14
+ class ComposeGreeting :
15
+ def __init__ (self ):
16
+ self .test_service = TestService ()
17
+
18
+ @activity .defn
19
+ async def compose_greeting (self , input : ComposeGreetingInput ) -> str :
20
+ # If this raises an exception because it's not done yet, the activity will
21
+ # continually be scheduled for retry
22
+ return await self .test_service .get_service_result (input )
Original file line number Diff line number Diff line change 3
3
from temporalio .client import Client
4
4
from temporalio .worker import Worker
5
5
6
- from polling .infrequent .activities import compose_greeting
6
+ from polling .infrequent .activities import ComposeGreeting
7
7
from polling .infrequent .workflows import GreetingWorkflow
8
8
9
9
10
10
async def main ():
11
11
client = await Client .connect ("localhost:7233" )
12
-
12
+ activities = ComposeGreeting ()
13
13
worker = Worker (
14
14
client ,
15
15
task_queue = "infrequent-activity-retry-task-queue" ,
16
16
workflows = [GreetingWorkflow ],
17
- activities = [compose_greeting ],
17
+ activities = [activities . compose_greeting ],
18
18
)
19
19
await worker .run ()
20
20
Original file line number Diff line number Diff line change 4
4
from temporalio .common import RetryPolicy
5
5
6
6
with workflow .unsafe .imports_passed_through ():
7
- from polling .infrequent .activities import ComposeGreetingInput , compose_greeting
7
+ from polling .infrequent .activities import ComposeGreeting , ComposeGreetingInput
8
8
9
9
10
10
@workflow .defn
11
11
class GreetingWorkflow :
12
12
@workflow .run
13
13
async def run (self , name : str ) -> str :
14
- return await workflow .execute_activity (
15
- compose_greeting ,
14
+ return await workflow .execute_activity_method (
15
+ ComposeGreeting . compose_greeting ,
16
16
ComposeGreetingInput ("Hello" , name ),
17
17
start_to_close_timeout = timedelta (seconds = 2 ),
18
18
retry_policy = RetryPolicy (
Original file line number Diff line number Diff line change 1
1
class TestService :
2
- def __init__ (self , attempt = 0 , error_attempts = 5 ):
3
- self .try_attempts = attempt
4
- self .error_attempts = error_attempts
2
+ def __init__ (self ):
3
+ self .try_attempts = 0
4
+ self .error_attempts = 5
5
5
6
6
async def get_service_result (self , input ):
7
7
print (
You can’t perform that action at this time.
0 commit comments