@@ -49,7 +49,7 @@ def _restart(self, event):
4949
5050To kick off the rolling restart, emit this library's AcquireLock event. The simplest way
5151to do so would be with an action, though it might make sense to acquire the lock in
52- response to another event.
52+ response to another event.
5353
5454```python
5555 def _on_trigger_restart(self, event):
@@ -88,7 +88,7 @@ def _on_trigger_restart(self, event):
8888
8989# Increment this PATCH version before using `charmcraft publish-lib` or reset
9090# to 0 if you are raising the major API version
91- LIBPATCH = 5
91+ LIBPATCH = 7
9292
9393
9494class LockNoRelationError (Exception ):
@@ -182,6 +182,7 @@ def _state(self) -> LockState:
182182 # Active acquire request.
183183 return LockState .ACQUIRE
184184
185+ logger .debug ("Lock state: %s %s" , unit_state , app_state )
185186 return app_state # Granted or unset/released
186187
187188 @_state .setter
@@ -202,21 +203,27 @@ def _state(self, state: LockState):
202203 if state is LockState .IDLE :
203204 self .relation .data [self .app ].update ({str (self .unit ): state .value })
204205
206+ logger .debug ("state: %s" , state .value )
207+
205208 def acquire (self ):
206209 """Request that a lock be acquired."""
207210 self ._state = LockState .ACQUIRE
211+ logger .debug ("Lock acquired." )
208212
209213 def release (self ):
210214 """Request that a lock be released."""
211215 self ._state = LockState .RELEASE
216+ logger .debug ("Lock released." )
212217
213218 def clear (self ):
214219 """Unset a lock."""
215220 self ._state = LockState .IDLE
221+ logger .debug ("Lock cleared." )
216222
217223 def grant (self ):
218224 """Grant a lock to a unit."""
219225 self ._state = LockState .GRANTED
226+ logger .debug ("Lock granted." )
220227
221228 def is_held (self ):
222229 """This unit holds the lock."""
@@ -266,9 +273,11 @@ def __init__(self, handle, callback_override: Optional[str] = None):
266273 self .callback_override = callback_override or ""
267274
268275 def snapshot (self ):
276+ """Snapshot of lock event."""
269277 return {"callback_override" : self .callback_override }
270278
271279 def restore (self , snapshot ):
280+ """Restores lock event."""
272281 self .callback_override = snapshot ["callback_override" ]
273282
274283
@@ -288,7 +297,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable):
288297 charm: the charm we are attaching this to.
289298 relation: an identifier, by convention based on the name of the relation in the
290299 metadata.yaml, which identifies this instance of RollingOperatorsFactory,
291- distinct from other instances that may be hanlding other events.
300+ distinct from other instances that may be handling other events.
292301 callback: a closure to run when we have a lock. (It must take a CharmBase object and
293302 EventBase object as args.)
294303 """
@@ -309,6 +318,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable):
309318 self .framework .observe (charm .on [self .name ].acquire_lock , self ._on_acquire_lock )
310319 self .framework .observe (charm .on [self .name ].run_with_lock , self ._on_run_with_lock )
311320 self .framework .observe (charm .on [self .name ].process_locks , self ._on_process_locks )
321+ self .framework .observe (charm .on .leader_elected , self ._on_process_locks )
312322
313323 def _callback (self : CharmBase , event : EventBase ) -> None :
314324 """Placeholder for the function that actually runs our event.
@@ -381,7 +391,7 @@ def _on_acquire_lock(self: CharmBase, event: ActionEvent):
381391 """Request a lock."""
382392 try :
383393 Lock (self ).acquire () # Updates relation data
384- # emit relation changed event in the edge case where aquire does not
394+ # emit relation changed event in the edge case where acquire does not
385395 relation = self .model .get_relation (self .name )
386396
387397 # persist callback override for eventual run
0 commit comments