Skip to content

Commit

Permalink
Add explicit parameters for AIOHttpConnection and AsyncTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
V1NAY8 committed Aug 16, 2021
1 parent 74320f4 commit af9515b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions elasticsearch/_async/http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(
self,
host="localhost",
port=None,
url_prefix="",
timeout=10,
http_auth=None,
use_ssl=False,
verify_certs=VERIFY_CERTS_DEFAULT,
Expand Down Expand Up @@ -138,6 +140,8 @@ def __init__(
super().__init__(
host=host,
port=port,
url_prefix=url_prefix,
timeout=timeout,
use_ssl=use_ssl,
headers=headers,
http_compress=http_compress,
Expand Down
2 changes: 2 additions & 0 deletions elasticsearch/_async/http_aiohttp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class AIOHttpConnection(AsyncConnection):
self,
host: str = ...,
port: Optional[int] = ...,
url_prefix: str = ...,
timeout: int = ...,
http_auth: Optional[Any] = ...,
use_ssl: bool = ...,
verify_certs: bool = ...,
Expand Down
45 changes: 42 additions & 3 deletions elasticsearch/_async/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import sys
from itertools import chain

from ..connection_pool import ConnectionPool
from ..exceptions import (
ConnectionError,
ConnectionTimeout,
SerializationError,
TransportError,
UnsupportedProductError,
)
from ..transport import Transport
from ..serializer import JSONSerializer
from ..transport import Transport, get_host_info
from .compat import get_running_loop
from .http_aiohttp import AIOHttpConnection

Expand All @@ -44,7 +46,26 @@ class AsyncTransport(Transport):

DEFAULT_CONNECTION_CLASS = AIOHttpConnection

def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
def __init__(
self,
hosts,
connection_class=None,
connection_pool_class=ConnectionPool,
host_info_callback=get_host_info,
sniff_on_start=False,
sniffer_timeout=None,
sniff_timeout=0.1,
sniff_on_connection_fail=False,
serializer=JSONSerializer(),
serializers=None,
default_mimetype="application/json",
max_retries=3,
retry_on_status=(502, 503, 504),
retry_on_timeout=False,
send_get_body_as="GET",
meta_header=True,
**kwargs
):
"""
:arg hosts: list of dictionaries, each containing keyword arguments to
create a `connection_class` instance
Expand Down Expand Up @@ -77,6 +98,8 @@ def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
don't support passing bodies with GET requests. If you set this to
'POST' a POST method will be used instead, if to 'source' then the body
will be serialized and passed as a query parameter `source`.
:arg meta_header: If True will send the 'X-Elastic-Client-Meta' HTTP header containing
simple client metadata. Setting to False will disable the header. Defaults to True.
Any extra keyword arguments will be passed to the `connection_class`
when creating and instance unless overridden by that connection's
Expand All @@ -88,7 +111,23 @@ def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
self._sniff_on_start_event = None # type: asyncio.Event

super(AsyncTransport, self).__init__(
*args, hosts=[], sniff_on_start=False, **kwargs
hosts=[],
connection_class=connection_class,
connection_pool_class=connection_pool_class,
host_info_callback=host_info_callback,
sniff_on_start=False,
sniffer_timeout=sniffer_timeout,
sniff_timeout=sniff_timeout,
sniff_on_connection_fail=sniff_on_connection_fail,
serializer=serializer,
serializers=serializers,
default_mimetype=default_mimetype,
max_retries=max_retries,
retry_on_status=retry_on_status,
retry_on_timeout=retry_on_timeout,
send_get_body_as=send_get_body_as,
meta_header=meta_header,
**kwargs,
)

# Don't enable sniffing on Cloud instances.
Expand Down
1 change: 1 addition & 0 deletions elasticsearch/_async/transport.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AsyncTransport(object):
retry_on_status: Collection[int] = ...,
retry_on_timeout: bool = ...,
send_get_body_as: str = ...,
meta_header: bool = ...,
**kwargs: Any
) -> None: ...
def add_connection(self, host: Any) -> None: ...
Expand Down

0 comments on commit af9515b

Please sign in to comment.