11import asyncio
22from concurrent .futures import ThreadPoolExecutor
3+ import threading
34
45from temporalio import activity
56from temporalio .client import Client
1314
1415from custom_metric .activity import print_and_sleep
1516from custom_metric .workflow import StartTwoActivitiesWorkflow
17+ from custom_metric .shared import user_id
1618
1719
1820class SimpleWorkerInterceptor (Interceptor ):
1921 def intercept_activity (
2022 self , next : ActivityInboundInterceptor
2123 ) -> ActivityInboundInterceptor :
24+ user_id .set (activity .info ().activity_id ) # Set a user ID for the activity context
2225 return CustomScheduleToStartInterceptor (next )
2326
2427
@@ -32,6 +35,9 @@ async def execute_activity(self, input: ExecuteActivityInput):
3235 # Could do the original schedule time instead of current attempt
3336 # schedule_to_start_second_option = activity.info().started_time - activity.info().scheduled_time
3437
38+ # print the thread name for debugging
39+ print (f"In the activity interceptor. in thread { threading .current_thread ().name } " )
40+
3541 meter = activity .metric_meter ()
3642 histogram = meter .create_histogram_timedelta (
3743 "custom_activity_schedule_to_start_latency" ,
@@ -60,8 +66,8 @@ async def main():
6066 activities = [print_and_sleep ],
6167 # only one activity executor with two concurrently scheduled activities
6268 # to force a nontrivial schedule to start times
63- activity_executor = ThreadPoolExecutor (1 ),
64- max_concurrent_activities = 1 ,
69+ activity_executor = ThreadPoolExecutor (10 ),
70+ max_concurrent_activities = 10 ,
6571 )
6672
6773 await worker .run ()
0 commit comments