File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -446,18 +446,27 @@ def is_restart_pending(self) -> bool:
446
446
# The current Patroni 3.2.2 has wired behaviour: it temporary flag pending_restart=True
447
447
# on any changes to REST API, which is gone within a second but long enough to be
448
448
# cougth by charm. Sleep 2 seconds as a protection here until Patroni 3.3.0 upgrade
449
- sleep (2 )
449
+ pending_restart = self ._get_patroni_restart_pending ()
450
+ if pending_restart :
451
+ # The current Patroni 3.2.2 has wired behaviour: it temporary flag pending_restart=True
452
+ # on any changes to REST API, which is gone within a second but long enough to be
453
+ # cougth by charm. Sleep 2 seconds as a protection here until Patroni 3.3.0 upgrade.
454
+ # Repeat the request to make sure pending_restart flag is still here
455
+ sleep (2 )
456
+ pending_restart = self ._get_patroni_restart_pending ()
457
+
458
+ return pending_restart
459
+
460
+ def _get_patroni_restart_pending (self ) -> bool :
461
+ """Returns whether the Patroni flag pending_restart on REST API."""
450
462
r = requests .get (
451
463
f"{ self ._patroni_url } /patroni" ,
452
464
verify = self .verify ,
453
465
timeout = API_REQUEST_TIMEOUT ,
454
466
auth = self ._patroni_auth ,
455
467
)
456
- try :
457
- pending_restart = r .json ()["pending_restart" ]
458
- except KeyError :
459
- pending_restart = False
460
- pass
468
+
469
+ pending_restart = r .json ().get ("pending_restart" , False )
461
470
logger .debug (
462
471
f"API is_restart_pending ({ pending_restart } ): %s (%s)" ,
463
472
r ,
You can’t perform that action at this time.
0 commit comments