File tree Expand file tree Collapse file tree 4 files changed +16
-15
lines changed Expand file tree Collapse file tree 4 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,12 @@ class ComposeGreetingInput:
1010 greeting : str
1111 name : str
1212
13+ class ComposeGreeting :
14+ def __init__ (self , test_service : TestService = None ):
15+ self .test_service = test_service or TestService ()
1316
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 )
17+ @activity .defn
18+ async def compose_greeting (self , input : ComposeGreetingInput ) -> str :
19+ # If this raises an exception because it's not done yet, the activity will
20+ # continually be scheduled for retry
21+ return await self .test_service .get_service_result (input )
Original file line number Diff line number Diff line change 33from temporalio .client import Client
44from temporalio .worker import Worker
55
6- from polling .infrequent .activities import compose_greeting
6+ from polling .infrequent .activities import ComposeGreeting
77from polling .infrequent .workflows import GreetingWorkflow
88
99
1010async def main ():
1111 client = await Client .connect ("localhost:7233" )
12-
12+ activities = ComposeGreeting ()
1313 worker = Worker (
1414 client ,
1515 task_queue = "infrequent-activity-retry-task-queue" ,
1616 workflows = [GreetingWorkflow ],
17- activities = [compose_greeting ],
17+ activities = [activities . compose_greeting ],
1818 )
1919 await worker .run ()
2020
Original file line number Diff line number Diff line change 44from temporalio .common import RetryPolicy
55
66with workflow .unsafe .imports_passed_through ():
7- from polling .infrequent .activities import ComposeGreetingInput , compose_greeting
7+ from polling .infrequent .activities import ComposeGreetingInput , ComposeGreeting
88
99
1010@workflow .defn
1111class GreetingWorkflow :
1212 @workflow .run
1313 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 ,
1616 ComposeGreetingInput ("Hello" , name ),
1717 start_to_close_timeout = timedelta (seconds = 2 ),
1818 retry_policy = RetryPolicy (
Original file line number Diff line number Diff line change 11class TestService :
2- def __init__ (self , attempt = 0 , error_attempts = 5 ):
3- self .try_attempts = attempt
2+ def __init__ (self , error_attempts = 5 ):
3+ self .try_attempts = 0
44 self .error_attempts = error_attempts
55
66 async def get_service_result (self , input ):
You can’t perform that action at this time.
0 commit comments