|
24 | 24 | from ai.backend.manager.data.session.types import SchedulingResult |
25 | 25 | from ai.backend.manager.models.routing import RoutingRow |
26 | 26 | from ai.backend.manager.models.routing.conditions import RouteConditions |
| 27 | +from ai.backend.manager.repositories.base import BatchQuerier, NoPagination, QueryCondition |
27 | 28 | from ai.backend.manager.repositories.base.creator import BulkCreator |
28 | 29 | from ai.backend.manager.repositories.base.updater import BatchUpdater |
29 | 30 | from ai.backend.manager.repositories.deployment import DeploymentRepository |
@@ -197,11 +198,16 @@ async def process_route_lifecycle( |
197 | 198 | lock_lifetime = self._config_provider.config.manager.session_schedule_lock_lifetime |
198 | 199 | await stack.enter_async_context(self._lock_factory(handler.lock_id, lock_lifetime)) |
199 | 200 |
|
200 | | - # Get routes by target lifecycle + health statuses |
| 201 | + # Get routes by target lifecycle + health (+ optional traffic) statuses |
201 | 202 | target = handler.target_statuses() |
202 | | - routes = await self._deployment_repository.get_routes_by_statuses( |
203 | | - target.lifecycle, |
204 | | - target.health, |
| 203 | + conditions: list[QueryCondition] = [ |
| 204 | + RouteConditions.by_lifecycle_statuses(target.lifecycle), |
| 205 | + RouteConditions.by_health_statuses(target.health), |
| 206 | + ] |
| 207 | + if target.traffic is not None: |
| 208 | + conditions.append(RouteConditions.by_traffic_statuses(target.traffic)) |
| 209 | + routes = await self._deployment_repository.search_route_datas( |
| 210 | + querier=BatchQuerier(pagination=NoPagination(), conditions=conditions), |
205 | 211 | ) |
206 | 212 | if not routes: |
207 | 213 | log.trace("No routes to process for handler: {}", handler.name()) |
@@ -230,9 +236,14 @@ async def _process_observer(self, observer: RouteObserver) -> None: |
230 | 236 | changing route status in DB. |
231 | 237 | """ |
232 | 238 | try: |
233 | | - routes = await self._deployment_repository.get_routes_by_statuses( |
234 | | - [RouteStatus.RUNNING], |
235 | | - list(RouteHealthStatus), |
| 239 | + routes = await self._deployment_repository.search_route_datas( |
| 240 | + querier=BatchQuerier( |
| 241 | + pagination=NoPagination(), |
| 242 | + conditions=[ |
| 243 | + RouteConditions.by_lifecycle_statuses([RouteStatus.RUNNING]), |
| 244 | + RouteConditions.by_health_statuses(list(RouteHealthStatus)), |
| 245 | + ], |
| 246 | + ), |
236 | 247 | ) |
237 | 248 | if not routes: |
238 | 249 | return |
|
0 commit comments