Skip to content

Commit ab0f432

Browse files
odesenfanshoh
authored andcommitted
Feature: VM cache did not support connecting through a Unix socket
Problem: the user can only specify the URL of the cache or a complete aiohttp client session object. Solution: mirror what is done for the `AlephClient` class and allow a `unix_socket` parameter in the constructor of `VmCache` to build the client session correctly for the user.
1 parent b409dd2 commit ab0f432

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/aleph/sdk/vm/cache.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pydantic import AnyHttpUrl
88

99
from ..conf import settings
10+
from ..utils import check_unix_socket_valid
1011

1112
CacheKey = NewType("CacheKey", str)
1213

@@ -52,8 +53,22 @@ def __init__(
5253
self,
5354
session: Optional[aiohttp.ClientSession] = None,
5455
connector_url: Optional[AnyHttpUrl] = None,
56+
unix_socket: Optional[str] = None,
5557
):
56-
self.session = session or aiohttp.ClientSession(base_url=connector_url)
58+
if session:
59+
self.session = session
60+
else:
61+
unix_socket_path = unix_socket or settings.API_UNIX_SOCKET
62+
if unix_socket_path:
63+
check_unix_socket_valid(unix_socket_path)
64+
connector = aiohttp.UnixConnector(path=unix_socket_path)
65+
else:
66+
connector = None
67+
68+
self.session = aiohttp.ClientSession(
69+
base_url=connector_url, connector=connector
70+
)
71+
5772
self.cache = {}
5873
self.api_host = connector_url if connector_url else settings.API_HOST
5974

0 commit comments

Comments
 (0)