python-databases 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_databases/elasticsearch_infrastructure/elasticsearch.py +39 -8
- {python_databases-1.1.0.dist-info → python_databases-1.2.0.dist-info}/METADATA +2 -2
- {python_databases-1.1.0.dist-info → python_databases-1.2.0.dist-info}/RECORD +6 -6
- {python_databases-1.1.0.dist-info → python_databases-1.2.0.dist-info}/WHEEL +1 -1
- {python_databases-1.1.0.dist-info → python_databases-1.2.0.dist-info}/licenses/LICENSE +0 -0
- {python_databases-1.1.0.dist-info → python_databases-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -55,13 +55,22 @@ class ElasticSearch(ABC):
|
|
|
55
55
|
tracer = get_logger("elasticsearch")
|
|
56
56
|
tracer.setLevel(debug_level)
|
|
57
57
|
|
|
58
|
-
def _set_list_of_docs_quick(
|
|
58
|
+
def _set_list_of_docs_quick(
|
|
59
|
+
self,
|
|
60
|
+
list_of_docs: list[dict],
|
|
61
|
+
request_timeout: int = 600,
|
|
62
|
+
raise_on_error: bool = False,
|
|
63
|
+
) -> None:
|
|
64
|
+
failed_response_list = []
|
|
59
65
|
if failed_response := helpers.streaming_bulk(
|
|
60
|
-
|
|
66
|
+
self.elk_client, list_of_docs, raise_on_error=False, request_timeout=request_timeout, chunk_size=1000
|
|
61
67
|
):
|
|
62
68
|
for item in failed_response:
|
|
63
69
|
if item[1]["index"]["status"] != 201 or item[1]["index"]["_shards"]["failed"] > 0:
|
|
64
70
|
self.logger.debug(f"Failed document: \n{item}")
|
|
71
|
+
failed_response_list.append(item)
|
|
72
|
+
if raise_on_error and failed_response_list:
|
|
73
|
+
raise Exception(f"Failed to report {len(failed_response_list)} documents")
|
|
65
74
|
|
|
66
75
|
def _set_list_of_docs_safe(self, list_of_docs: list[dict]) -> None:
|
|
67
76
|
success_response, failed_response = helpers.bulk(self.elk_client, list_of_docs)
|
|
@@ -73,11 +82,21 @@ class ElasticSearch(ABC):
|
|
|
73
82
|
f"The documents that were not reported successfully: {failed_response}"
|
|
74
83
|
)
|
|
75
84
|
|
|
76
|
-
def post_list_of_docs(
|
|
85
|
+
def post_list_of_docs(
|
|
86
|
+
self,
|
|
87
|
+
list_of_docs: list[dict],
|
|
88
|
+
request_timeout: int = 600,
|
|
89
|
+
quick: bool = False,
|
|
90
|
+
raise_on_error: bool = False
|
|
91
|
+
) -> None:
|
|
77
92
|
self.logger.info("Start to report the documents to ELK")
|
|
78
93
|
|
|
79
94
|
if quick:
|
|
80
|
-
self._set_list_of_docs_quick(
|
|
95
|
+
self._set_list_of_docs_quick(
|
|
96
|
+
list_of_docs=list_of_docs,
|
|
97
|
+
request_timeout=request_timeout,
|
|
98
|
+
raise_on_error=raise_on_error
|
|
99
|
+
)
|
|
81
100
|
else:
|
|
82
101
|
self._set_list_of_docs_safe(list_of_docs=list_of_docs)
|
|
83
102
|
self.logger.info("Finish to report the documents to ELK")
|
|
@@ -135,16 +154,27 @@ class ElasticSearch(ABC):
|
|
|
135
154
|
return list_of_docs
|
|
136
155
|
|
|
137
156
|
def post_list_of_docs_as_bulk_chunk(
|
|
138
|
-
self,
|
|
157
|
+
self,
|
|
158
|
+
list_of_docs: list[dict],
|
|
159
|
+
chunk_size: int = 1000,
|
|
160
|
+
time_sleep: int = 60,
|
|
161
|
+
quick: bool = False,
|
|
162
|
+
raise_on_error: bool = False,
|
|
139
163
|
) -> None:
|
|
140
164
|
for i in range(0, len(list_of_docs), chunk_size):
|
|
141
165
|
self.logger.info(f"index: {i} - {i + chunk_size} / {len(list_of_docs)}")
|
|
142
|
-
chunk = list_of_docs[i
|
|
143
|
-
self.post_list_of_docs(list_of_docs=chunk, quick=quick)
|
|
166
|
+
chunk = list_of_docs[i: i + chunk_size]
|
|
167
|
+
self.post_list_of_docs(list_of_docs=chunk, quick=quick, raise_on_error=raise_on_error)
|
|
144
168
|
time.sleep(time_sleep)
|
|
145
169
|
|
|
146
170
|
def fill_elk_index_as_bulk( # post_list_of_docs_as_bulk
|
|
147
|
-
self,
|
|
171
|
+
self,
|
|
172
|
+
data: list[dict],
|
|
173
|
+
doc_index_name: str,
|
|
174
|
+
chunk_size: int = 1000,
|
|
175
|
+
time_sleep: int = 1,
|
|
176
|
+
quick: bool = True,
|
|
177
|
+
raise_on_error: bool = False,
|
|
148
178
|
) -> None: # use as the main function to send data to the elastic search
|
|
149
179
|
list_of_docs = self._prepare_documents_for_bulk(
|
|
150
180
|
data=data,
|
|
@@ -156,6 +186,7 @@ class ElasticSearch(ABC):
|
|
|
156
186
|
chunk_size=chunk_size,
|
|
157
187
|
time_sleep=time_sleep,
|
|
158
188
|
quick=quick,
|
|
189
|
+
raise_on_error=raise_on_error,
|
|
159
190
|
)
|
|
160
191
|
|
|
161
192
|
def check_if_index_exists(self, index: str) -> bool:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-databases
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: A Python library for managing and interacting with multiple databases seamlessly.
|
|
5
5
|
Author: Avi Zaguri
|
|
6
6
|
License: MIT
|
|
@@ -10,7 +10,7 @@ Project-URL: Issues, https://github.com/aviz92/python-databases/issues
|
|
|
10
10
|
Keywords: development,databases,ORM,SQL,NoSQL,database management
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Topic :: System :: Logging
|
|
16
16
|
Requires-Python: >=3.12
|
|
@@ -2,12 +2,12 @@ python_databases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
|
|
|
2
2
|
python_databases/consts.py,sha256=ADn3PmhTXKBobtiVgDR4Tqq2Ncn_FTK0WjgREOLdBPs,33
|
|
3
3
|
python_databases/elasticsearch_infrastructure/__init__.py,sha256=U1orkPi0Pg-1rtY1CPSF4-eVRfrMr36qpT9VNKjBUw4,297
|
|
4
4
|
python_databases/elasticsearch_infrastructure/consts.py,sha256=tW4jgeUsf3FhqEpNHZQr3SjqPbuJjcWQDsSqxAvUYPg,98
|
|
5
|
-
python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=
|
|
5
|
+
python_databases/elasticsearch_infrastructure/elasticsearch.py,sha256=8Mu1li0AT0puqjSh8SQdP9Drv4lQDHGGcQ4YNlBeIs4,10739
|
|
6
6
|
python_databases/postgresql_infrastructure/__init__.py,sha256=yBjq7SLnNgnxW0DCQHEwCi_FrCNtjsJGJXIq7XtkUZg,150
|
|
7
7
|
python_databases/postgresql_infrastructure/consts.py,sha256=Fz19Qj-B9mPCTGInNygm2CPmY0nWiamWeEMrJsv-XB4,102
|
|
8
8
|
python_databases/postgresql_infrastructure/postgresql.py,sha256=tFdQr5IOPYbuqKE3r9oqSoNoGMbED5NSEy1anrUNEyY,3105
|
|
9
|
-
python_databases-1.
|
|
10
|
-
python_databases-1.
|
|
11
|
-
python_databases-1.
|
|
12
|
-
python_databases-1.
|
|
13
|
-
python_databases-1.
|
|
9
|
+
python_databases-1.2.0.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
|
|
10
|
+
python_databases-1.2.0.dist-info/METADATA,sha256=xlmPxDkSjI0xl5UPEFtvclI71101SED6KkF5JrTDAys,2463
|
|
11
|
+
python_databases-1.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
12
|
+
python_databases-1.2.0.dist-info/top_level.txt,sha256=fXcMUntaYJfKeFS7FjQ6DY4WVXYBsgdrDmhOudYs-vg,17
|
|
13
|
+
python_databases-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|