From 4b1ff5a4bb6319ebd3ad579b28dbc9adb078e083 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Tue, 24 Nov 2015 16:37:40 +0100 Subject: [PATCH] Code refactoring, per code review by Alex. --- patroni/postgresql.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 932634ed..47fd53d3 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -714,7 +714,7 @@ $$""".format(name, options), name, password, password) bbfailures = 0 maxfailures = 2 ret = 1 - while bbfailures < maxfailures: + for bbfailures in range(0, maxfailures): try: ret = subprocess.call(['pg_basebackup', '--pgdata=' + self.data_dir, '--xlog-method=stream', "--dbname=" + master_connection], env=env) @@ -724,9 +724,8 @@ $$""".format(name, options), name, password, password) except Exception as e: logger.error('Error when fetching backup with pg_basebackup: {0}'.format(e)) - bbfailures += 1 - if bbfailures < maxfailures: + if bbfailures < maxfailures - 1: logger.error('Trying again in 5 seconds') - time.sleep(5) + time.sleep(5) return ret