44import uuid
55from collections .abc import Callable
66from concurrent .futures import ThreadPoolExecutor
7- from typing import Any
7+ from typing import Any , overload
88
99from aiohttp import web
1010from temporalio .client import Client
@@ -99,10 +99,28 @@ def __init__(
9999 self .healthy = False
100100 self .health_check_port = health_check_port
101101
102+ @overload
102103 async def run (
103104 self ,
104105 activities : list [Callable ],
106+ * ,
105107 workflow : type ,
108+ ) -> None : ...
109+
110+ @overload
111+ async def run (
112+ self ,
113+ activities : list [Callable ],
114+ * ,
115+ workflows : list [type ],
116+ ) -> None : ...
117+
118+ async def run (
119+ self ,
120+ activities : list [Callable ],
121+ * ,
122+ workflow : type | None = None ,
123+ workflows : list [type ] | None = None ,
106124 ):
107125 await self .start_health_check_server ()
108126 await self ._register_agent ()
@@ -115,11 +133,14 @@ async def run(
115133 if debug_enabled :
116134 logger .info ("🐛 [WORKER] Temporal debug mode enabled - deadlock detection disabled" )
117135
136+ if workflow is None and workflows is None :
137+ raise ValueError ("Either workflow or workflows must be provided" )
138+
118139 worker = Worker (
119140 client = temporal_client ,
120141 task_queue = self .task_queue ,
121142 activity_executor = ThreadPoolExecutor (max_workers = self .max_workers ),
122- workflows = [workflow ],
143+ workflows = [workflow ] if workflows is None else workflows ,
123144 activities = activities ,
124145 workflow_runner = UnsandboxedWorkflowRunner (),
125146 max_concurrent_activities = self .max_concurrent_activities ,
0 commit comments