Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
production
building-knowledge-centre
building-dao
Commits
eb79f157
Commit
eb79f157
authored
Jan 27, 2021
by
Marc-André Santune
Browse files
cache registry information for 30 seconds
parent
a50c94cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
building_dao/settings.py
building_dao/settings.py
+14
-2
No files found.
building_dao/settings.py
View file @
eb79f157
"""Store settings"""
import
logging
from
MaxIcsRegistry
import
MaxIcsRegistry
from
cachetools
import
cached
,
LRUCache
,
TTLCache
class
Settings
:
"""Settings for BKC communication"""
def
__init__
(
self
,
staging
:
bool
=
False
,
registry
=
None
,
**
kwargs
)
->
None
:
self
.
logger
=
logging
.
getLogger
(
self
.
__class__
.
__name__
)
if
not
registry
:
self
.
logger
.
warning
(
"Registry is not set when initializing Building. Calling registry..."
)
self
.
logger
.
warning
(
"Registry is not set when initializing Building. Calling registry..."
)
registry
=
MaxIcsRegistry
.
from_env
(
staging
=
staging
)
building_center_info
=
registry
.
get_info
(
"building-knowledge-information-center"
)
building_center_info
=
self
.
_get_node_information
(
registry
=
registry
,
node_name
=
"building-knowledge-information-center"
)
self
.
api_key
=
next
(
iter
(
building_center_info
[
"api_in"
].
values
()))[
"key"
]
...
...
@@ -26,3 +33,8 @@ class Settings:
def
__str__
(
self
):
return
"Settings __dict__: %s"
%
str
(
self
.
__dict__
)
@
cached
(
cache
=
TTLCache
(
maxsize
=
1024
,
ttl
=
30
))
def
_get_node_information
(
self
,
registry
:
MaxIcsRegistry
,
node_name
:
str
):
node_info
=
registry
.
get_info
(
node_name
)
return
node_info
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