Skip to content

Commit 688b4d8

Browse files
committed
Fixed logging, tiny code improvements.
1 parent a04d394 commit 688b4d8

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

c8y_api/app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def get_item(key: str, dictionary: dict) -> str | None:
9393
info = get_item('Authorization', headers)
9494

9595
if not info:
96-
9796
keys = ", ".join([*headers.keys(), *cookies.keys()]) or "None"
9897
raise KeyError(f"Unable to resolve Authorization information. Found keys: {keys}.")
98+
9999
return info
100100

101101
@staticmethod

c8y_tk/app/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def __init__(
5151
startup_delay (float): A minimum delay before a newly added
5252
microservice is considered to be "added" (the callback
5353
invocation will be delayed by this).
54-
55-
5654
"""
5755
self._n = self._n + 1
5856
self._instance_name = f"{__name__}.{type(self).__name__}[{self._n}]"\
@@ -64,7 +62,7 @@ def __init__(
6462
self.callbacks = [(callback, blocking)] if callback else []
6563
self.callbacks_on_add = []
6664
self.callbacks_on_remove = []
67-
self._log = logging.Logger(self._instance_name)
65+
self._log = logging.getLogger(self._instance_name)
6866
self._executor = None
6967
self._callback_futures = set()
7068
self._listen_thread = None
@@ -121,10 +119,11 @@ def listen(self):
121119
This is blocking.
122120
"""
123121
# safely invoke a callback function blocking or non-blocking
124-
def invoke_callback(callback, is_blocking, arg):
122+
def invoke_callback(callback, is_blocking, _, arg):
125123
def safe_invoke(a):
126124
# pylint: disable=broad-exception-caught
127125
try:
126+
self._log.debug(f"Invoking callback: {callback}")
128127
callback(a)
129128
except Exception as error:
130129
self._log.error(f"Uncaught exception in callback: {error}", exc_info=error)
@@ -154,23 +153,24 @@ def safe_invoke(a):
154153
removed = last_subscribers - current_subscribers
155154
# run 'removed' callbacks
156155
for tenant_id in removed:
157-
self._log.info(f"Tenant subscription removed: ${tenant_id}.")
156+
self._log.info(f"Tenant subscription removed: {tenant_id}.")
158157
for fun, blocking in self.callbacks_on_remove:
159-
invoke_callback(fun, blocking, tenant_id)
158+
invoke_callback(fun, blocking, 'Removed', tenant_id)
160159
# wait remaining time for startup delay
161160
if added and self.startup_delay:
162161
min_startup_delay = self.startup_delay - (time.monotonic() - now)
163162
if min_startup_delay > 0:
164163
time.sleep(min_startup_delay)
165164
# run 'added' callbacks
166165
for tenant_id in added:
167-
self._log.info(f"Tenant subscription added: ${tenant_id}.")
166+
self._log.info(f"Tenant subscription added: {tenant_id}.")
168167
for fun, blocking in self.callbacks_on_add:
169-
invoke_callback(fun, blocking, tenant_id)
168+
invoke_callback(fun, blocking, 'Added', tenant_id)
170169
# run 'any' callbacks
171170
if added or removed:
171+
self._log.info(f"Tenant subscriptions changed: {current_subscribers}.")
172172
for fun, blocking in self.callbacks:
173-
invoke_callback(fun, blocking, current_subscribers)
173+
invoke_callback(fun, blocking, None, current_subscribers)
174174
# set new baseline
175175
last_subscribers = current_subscribers
176176
# schedule next run, skip if already exceeded

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def init(c):
4848
def lint(c, scope='all'):
4949
"""Run PyLint."""
5050
if scope == 'all':
51-
scope = 'c8y_api c8y_tk tests integration_tests samples'
51+
scope = 'c8y_api/ c8y_tk tests integration_tests samples'
5252
c.run(f'pylint --rcfile pylintrc --fail-under=9 {scope}')
5353

5454

0 commit comments

Comments
 (0)