Skip to content

Commit a143622

Browse files
committed
remove options to simplify
1 parent 13a09dd commit a143622

12 files changed

Lines changed: 48 additions & 75 deletions

livekit-api/livekit/api/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
from .twirp_client import TwirpError, TwirpErrorCode
4040
from .livekit_api import LiveKitAPI
41-
from ._failover import FailoverOptions
4241
from .access_token import (
4342
InferenceGrants,
4443
ObservabilityGrants,
@@ -67,5 +66,4 @@
6766
"WebhookReceiver",
6867
"TwirpError",
6968
"TwirpErrorCode",
70-
"FailoverOptions",
7169
]

livekit-api/livekit/api/_failover.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,27 @@
2424

2525
import time
2626
from dataclasses import dataclass
27-
from typing import Dict, List, Optional, TypedDict
27+
from typing import Dict, List, Optional
2828
from urllib.parse import urlparse
2929

3030
import aiohttp
3131

32-
_DEFAULT_MAX_ATTEMPTS = 3
33-
_DEFAULT_BACKOFF_BASE = 0.2
32+
FAILOVER_MAX_ATTEMPTS = 3
33+
FAILOVER_BACKOFF_BASE = 0.2 # seconds
3434

3535

36-
class FailoverOptions(TypedDict, total=False):
37-
"""Region-failover tuning, passed as the ``failover`` argument. Use it as a
38-
plain dict, e.g. ``failover={"max_attempts": 5}``. All keys are optional.
39-
40-
Keys:
41-
max_attempts: total number of attempts including the initial request —
42-
the original host plus up to ``max_attempts - 1`` fallback regions.
43-
Defaults to 3. Set to 1 to disable failover (a single attempt).
44-
backoff_base: seconds before the first retry; each subsequent retry
45-
doubles it. Defaults to 0.2.
46-
"""
47-
48-
max_attempts: int
49-
backoff_base: float
50-
51-
52-
def failover_attempts(failover: Optional[FailoverOptions], host: Optional[str]) -> int:
53-
"""Total request attempts including the initial one; 1 means no failover.
54-
55-
With no config (``None``) failover is enabled only for LiveKit Cloud hosts.
56-
An explicit config enables it for any host; ``max_attempts=1`` disables it.
36+
def failover_attempts(enabled: bool, host: Optional[str], force: bool = False) -> int:
37+
"""Total request attempts for a host; 1 means no failover. Failover only
38+
engages when enabled and the host is a LiveKit Cloud domain. ``force``
39+
bypasses the cloud-host check and is for internal testing only.
5740
"""
58-
if failover is None:
59-
return _DEFAULT_MAX_ATTEMPTS if (bool(host) and is_cloud(host)) else 1 # type: ignore[arg-type]
60-
return max(1, failover.get("max_attempts", _DEFAULT_MAX_ATTEMPTS))
61-
62-
63-
def failover_backoff_base(failover: Optional[FailoverOptions]) -> float:
64-
return (failover or {}).get("backoff_base", _DEFAULT_BACKOFF_BASE)
41+
if enabled and (force or (bool(host) and is_cloud(host))):
42+
return FAILOVER_MAX_ATTEMPTS
43+
return 1
6544

6645

6746
def is_cloud(host: str) -> bool:
68-
# Auto mode only enables failover for LiveKit Cloud project domains.
47+
# Failover only engages for LiveKit Cloud project domains.
6948
return host.endswith(".livekit.cloud")
7049

7150

livekit-api/livekit/api/_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import aiohttp
44
from abc import ABC
55
from .twirp_client import TwirpClient
6-
from ._failover import FailoverOptions
7-
from typing import Optional
86
from .access_token import AccessToken, VideoGrants, SIPGrants
97

108
AUTHORIZATION = "authorization"
@@ -17,7 +15,7 @@ def __init__(
1715
host: str,
1816
api_key: str,
1917
api_secret: str,
20-
failover: Optional[FailoverOptions] = None,
18+
failover: bool = True,
2119
):
2220
self._client = TwirpClient(session, host, "livekit", failover=failover)
2321
self.api_key = api_key

livekit-api/livekit/api/agent_dispatch_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
ListAgentDispatchResponse,
99
)
1010
from ._service import Service
11-
from ._failover import FailoverOptions
1211
from .access_token import VideoGrants
1312

1413
SVC = "AgentDispatchService"
@@ -33,7 +32,7 @@ def __init__(
3332
url: str,
3433
api_key: str,
3534
api_secret: str,
36-
failover: Optional[FailoverOptions] = None,
35+
failover: bool = True,
3736
):
3837
super().__init__(session, url, api_key, api_secret, failover=failover)
3938

livekit-api/livekit/api/connector_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
ConnectTwilioCallResponse,
1818
)
1919
from ._service import Service
20-
from ._failover import FailoverOptions
21-
from typing import Optional
2220
from .access_token import VideoGrants
2321

2422
SVC = "Connector"
@@ -43,7 +41,7 @@ def __init__(
4341
url: str,
4442
api_key: str,
4543
api_secret: str,
46-
failover: Optional[FailoverOptions] = None,
44+
failover: bool = True,
4745
):
4846
super().__init__(session, url, api_key, api_secret, failover=failover)
4947

livekit-api/livekit/api/egress_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
ListEgressResponse,
1414
)
1515
from ._service import Service
16-
from ._failover import FailoverOptions
17-
from typing import Optional
1816
from .access_token import VideoGrants
1917

2018
SVC = "Egress"
@@ -41,7 +39,7 @@ def __init__(
4139
url: str,
4240
api_key: str,
4341
api_secret: str,
44-
failover: Optional[FailoverOptions] = None,
42+
failover: bool = True,
4543
):
4644
super().__init__(session, url, api_key, api_secret, failover=failover)
4745

livekit-api/livekit/api/ingress_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
ListIngressResponse,
99
)
1010
from ._service import Service
11-
from ._failover import FailoverOptions
12-
from typing import Optional
1311
from .access_token import VideoGrants
1412

1513
SVC = "Ingress"
@@ -36,7 +34,7 @@ def __init__(
3634
url: str,
3735
api_key: str,
3836
api_secret: str,
39-
failover: Optional[FailoverOptions] = None,
37+
failover: bool = True,
4038
):
4139
super().__init__(session, url, api_key, api_secret, failover=failover)
4240

livekit-api/livekit/api/livekit_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from .sip_service import SipService
77
from .agent_dispatch_service import AgentDispatchService
88
from .connector_service import ConnectorService
9-
from ._failover import FailoverOptions
109
from typing import Any, Optional
1110

1211

@@ -32,7 +31,7 @@ def __init__(
3231
*,
3332
timeout: Optional[aiohttp.ClientTimeout] = None,
3433
session: Optional[aiohttp.ClientSession] = None,
35-
failover: Optional[FailoverOptions] = None,
34+
failover: bool = True,
3635
):
3736
"""Create a new LiveKitAPI instance.
3837

livekit-api/livekit/api/room_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626
from livekit.protocol.models import Room, ParticipantInfo
2727
from ._service import Service
28-
from ._failover import FailoverOptions
2928
from typing import Optional
3029
from .access_token import VideoGrants
3130

@@ -53,7 +52,7 @@ def __init__(
5352
url: str,
5453
api_key: str,
5554
api_secret: str,
56-
failover: Optional[FailoverOptions] = None,
55+
failover: bool = True,
5756
):
5857
super().__init__(session, url, api_key, api_secret, failover=failover)
5958

livekit-api/livekit/api/sip_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
SIPTransport,
3636
)
3737
from ._service import Service
38-
from ._failover import FailoverOptions
3938
from .access_token import VideoGrants, SIPGrants
4039

4140
SVC = "SIP"
@@ -60,7 +59,7 @@ def __init__(
6059
url: str,
6160
api_key: str,
6261
api_secret: str,
63-
failover: Optional[FailoverOptions] = None,
62+
failover: bool = True,
6463
):
6564
super().__init__(session, url, api_key, api_secret, failover=failover)
6665

0 commit comments

Comments
 (0)