@@ -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
0 commit comments