diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2026-04-19 22:14:41 +0100 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2026-04-19 22:14:41 +0100 |
| commit | 001aa38fc8b998171493271c850836506be2bc14 (patch) | |
| tree | b2de6834a77d0e189e296c7ef61d6afc6350d001 /autoBackup/autoBackup.py | |
| parent | 4db626520a63d3f4250c15bf244d9f42f8fde80a (diff) | |
| download | BetterZFSReplication-001aa38fc8b998171493271c850836506be2bc14.tar.gz BetterZFSReplication-001aa38fc8b998171493271c850836506be2bc14.zip | |
Diffstat (limited to 'autoBackup/autoBackup.py')
| -rw-r--r-- | autoBackup/autoBackup.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/autoBackup/autoBackup.py b/autoBackup/autoBackup.py index d88c650..808fd76 100644 --- a/autoBackup/autoBackup.py +++ b/autoBackup/autoBackup.py @@ -43,8 +43,17 @@ class TrueNASWebsocketsClient(truenas_api_client.JSONRPCClient): This implementation of the websockets API only works in 25.04 and onwards. """ + + num_retries = 3 + def __init__(self, host, username, password, replication_task_names = None, *args, **kwargs): - super().__init__(uri = "ws://%s/api/current" % host, *args, **kwargs) + for i in range(self.num_retries - 1): + try: + super().__init__(uri = "ws://%s/api/current" % host, *args, **kwargs) + except truenas_api_client.exc.ClientException as e: + logging.info("'%s', trying again..." % str(e)) + else: + break self.host = host self.username = username self.password = password @@ -55,10 +64,15 @@ class TrueNASWebsocketsClient(truenas_api_client.JSONRPCClient): self.replication_task_names = replication_task_names def __enter__(self): - o = super().__enter__() - # We are forced to use username/password instead of API keys if we're using self-certified certificates - auth = self.call("auth.login", self.username, self.password) - return o + for i in range(self.num_retries - 1): + try: + o = super().__enter__() + # We are forced to use username/password instead of API keys if we're using self-certified certificates + auth = self.call("auth.login", self.username, self.password) + return o + except truenas_api_client.exc.ClientException as e: + logging.info("'%s', trying again..." % str(e)) + raise ConnectionError("Connection timed out") def __exit__(self, *args, **kwargs): super().__exit__(*args, **kwargs) |
