proxy_renew.py
 1  # Copyright 2026 Alibaba Group Holding Ltd.
 2  #
 3  # Licensed under the Apache License, Version 2.0 (the "License");
 4  # you may not use this file except in compliance with the License.
 5  # You may obtain a copy of the License at
 6  #
 7  #     http://www.apache.org/licenses/LICENSE-2.0
 8  #
 9  # Unless required by applicable law or agreed to in writing, software
10  # distributed under the License is distributed on an "AS IS" BASIS,
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  # See the License for the specific language governing permissions and
13  # limitations under the License.
14  
15  """Server proxy path: enqueue renew work into ``RenewIntentConsumer`` (non-blocking)."""
16  
17  from __future__ import annotations
18  
19  from typing import TYPE_CHECKING, Optional
20  
21  if TYPE_CHECKING:
22      from opensandbox_server.config import AppConfig
23      from opensandbox_server.integrations.renew_intent.consumer import RenewIntentConsumer
24  
25  
26  class ProxyRenewCoordinator:
27      """Forward ``/sandboxes/{id}/proxy/...`` hits into the unified renew consumer."""
28  
29      def __init__(
30          self,
31          app_config: "AppConfig",
32          consumer: Optional["RenewIntentConsumer"],
33      ) -> None:
34          self._app_config = app_config
35          self._consumer = consumer
36  
37      def schedule(self, sandbox_id: str) -> None:
38          if not self._app_config.renew_intent.enabled or self._consumer is None:
39              return
40          self._consumer.submit_from_proxy(sandbox_id)