Skip to content

Commit

Permalink
Feature: VM cache did not support connecting through a Unix socket
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odesenfans committed Jul 6, 2023
1 parent 8aa9e6f commit 5a44411
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/aleph/sdk/vm/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import AnyHttpUrl

from ..conf import settings
from ..utils import check_unix_socket_valid

CacheKey = NewType("CacheKey", str)

Expand Down Expand Up @@ -52,8 +53,22 @@ def __init__(
self,
session: Optional[aiohttp.ClientSession] = None,
connector_url: Optional[AnyHttpUrl] = None,
unix_socket: Optional[str] = None,
):
self.session = session or aiohttp.ClientSession(base_url=connector_url)
if session:
self.session = session
else:
unix_socket_path = unix_socket or settings.API_UNIX_SOCKET
if unix_socket_path:
check_unix_socket_valid(unix_socket_path)
connector = aiohttp.UnixConnector(path=unix_socket_path)
else:
connector = None

self.session = aiohttp.ClientSession(
base_url=connector_url, connector=connector
)

self.cache = {}
self.api_host = connector_url if connector_url else settings.API_HOST

Expand Down

0 comments on commit 5a44411

Please sign in to comment.