Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
6db708d5
Commit
6db708d5
authored
1 year ago
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
4e2dfd87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
application/libs/flask_elasticsearch/elasticsearch.py
application/libs/flask_elasticsearch/elasticsearch.py
+11
-4
No files found.
application/libs/flask_elasticsearch/elasticsearch.py
View file @
6db708d5
...
...
@@ -10,6 +10,7 @@
# @Description :
"""
import
time
from
typing
import
Any
from
elasticsearch
import
Elasticsearch
...
...
@@ -65,11 +66,17 @@ class FlaskElasticsearch:
if
not
hasattr
(
ctx
,
'elasticsearch'
):
cfg
=
self
.
_get_config
()
ctx
.
elasticsearch
=
Elasticsearch
(
**
cfg
)
if
ctx
.
elasticsearch
.
ping
():
logger
.
info
(
'Connected to Elasticsearch'
)
# Retry connection on failure
for
i
in
range
(
5
):
# Retry up to 5 times
if
ctx
.
elasticsearch
.
ping
():
logger
.
info
(
'Connected to Elasticsearch'
)
break
else
:
logger
.
warning
(
f
'Attempt
{
i
+
1
}
to connect to Elasticsearch failed. Retrying...'
)
time
.
sleep
(
2
**
i
)
# Exponential backoff
else
:
logger
.
error
(
'Can not connect to Elasticsearch'
)
raise
ConnectionError
(
'Can not connect to Elasticsearch'
)
logger
.
error
(
'Can not connect to Elasticsearch
after 5 attempts
'
)
raise
ConnectionError
(
'Can not connect to Elasticsearch
after 5 attempts
'
)
return
getattr
(
ctx
.
elasticsearch
,
item
)
@
staticmethod
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment