Skip to content

Commit 3cb3880

Browse files
committed
Connection related fixes.
1 parent 62841ca commit 3cb3880

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### 2018-10-02 version 0.3
2+
3+
* Fixing connection reset issue when using multi-processing and a remote Elasticsearch server
4+
* Backward in compatible: changed the way Django configures Elasticsearch connection settings
5+
16
#### 2018-09-26 version 0.2
27

38
* Adding in post index create/rebuilt `Controller` hooks and associated Django signals

esdocs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import logging
2727

2828
__appname__ = __package__
29-
__version__ = "0.2"
29+
__version__ = "0.3"
3030

3131
app_version = "{}/{}".format(__appname__, __version__)
3232

esdocs/contrib/esdjango/apps.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ def ready(self):
1010
from ...utils import register_serializers
1111
from .settings import (
1212
ESDOCS_SERIALIZER_MODULES,
13-
ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS
13+
ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS,
14+
ESDOCS_USING,
15+
ESDOCS_CONNECTIONS
1416
)
1517

1618
from elasticsearch_dsl import connections
1719
# TODO: perhaps have some more elaborate multi-client creation steps here, based on settings?
1820
# then, we can pass in the 'default' client into `register_serializers`
19-
client = connections.create_connection(hosts=settings.ELASTICSEARCH_SERVER, timeout=20)
21+
connections.configure(**ESDOCS_CONNECTIONS)
22+
client = connections.get_connection(ESDOCS_USING)
2023

2124
# this loads the serializers and initializes compatibility hooks
2225
register_serializers(ESDOCS_SERIALIZER_MODULES, client=client)

esdocs/contrib/esdjango/settings.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from django.conf import settings
22

3+
ESDOCS_USING = getattr(settings, 'ESDOCS_USING', None) or 'default'
4+
ESDOCS_CONNECTIONS = getattr(settings, 'ESDOCS_CONNECTIONS', {}) or {
5+
'default': 'localhost:9200'
6+
}
7+
38
ESDOCS_SERIALIZER_MODULES = getattr(settings, 'ESDOCS_SERIALIZER_MODULES', [])
49
ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS = getattr(settings, 'ESDOCS_SERIALIZER_COMPATIBILITY_HOOKS', []) or [
510
'esdocs.contrib.esdjango.compatibility.manager',

esdocs/controller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def parallel_prep(self):
3434
# remove the existing connection (but keeps the _kwargs settings for it
3535
connections.connections._conns.pop(label, None)
3636
# recreate the connection using the retained _kwargs (view the source)
37-
connections.create_connection(label)
37+
connections.get_connection(label)
3838

3939
@property
4040
def indexes(self):

0 commit comments

Comments
 (0)