Blob Blame History Raw
From 08cebe5fae426c11b51e645754b87e4ec5737ef3 Mon Sep 17 00:00:00 2001
From: Ondrej Nosek <onosek@redhat.com>
Date: Tue, 22 Aug 2023 22:22:03 +0200
Subject: [PATCH 08/17] Make lookaside cache retries configurable

The number of attempts for lookaside cache network operations is now
configurable - there are new keys 'lookaside_attempts'
and 'lookaside_delay' in the configuration.
The Former expresses a maximum number of attempts to try the operation.
'0' or '1' is for a single try (no-retry).
The latter means an initial delay between network operation attempts.
Each attempt doubles the previous delay value. In seconds.

JIRA: RHELCMP-11210

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
---
 pyrpkg/__init__.py | 10 ++++++++--
 pyrpkg/cli.py      | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index f69f2ce..5928d47 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -110,7 +110,8 @@ class Commands(object):
                  build_client, user=None,
                  dist=None, target=None, quiet=False,
                  distgit_namespaced=False, realms=None, lookaside_namespaced=False,
-                 git_excludes=None, results_dir='root', allow_pre_generated_srpm=False):
+                 git_excludes=None, results_dir='root', allow_pre_generated_srpm=False,
+                 lookaside_attempts=None, lookaside_delay=None):
         """Init the object and some configuration details."""
 
         # Path to operate on, most often pwd
@@ -242,6 +243,10 @@ class Commands(object):
         # A Configuration value used in 'import_srpm' command (comes from the Copr team)
         # If pre-generated srpms are allowed, don't care specfile is processed by rpmautospec
         self.allow_pre_generated_srpm = allow_pre_generated_srpm
+        # number of attempts for lookaside network operations
+        self.lookaside_attempts = lookaside_attempts
+        # initial delay between network operation attempts. In seconds.
+        self.lookaside_delay = lookaside_delay
 
     # Define properties here
     # Properties allow us to "lazy load" various attributes, which also means
@@ -262,7 +267,8 @@ class Commands(object):
         """
         return CGILookasideCache(
             self.lookasidehash, self.lookaside, self.lookaside_cgi,
-            client_cert=self.cert_file, ca_cert=self.ca_cert)
+            client_cert=self.cert_file, ca_cert=self.ca_cert,
+            attempts=self.lookaside_attempts, delay=self.lookaside_delay)
 
     @property
     def path(self):
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 1bd7979..16298f0 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -261,7 +261,9 @@ class cliClient(object):
                                        realms=realms,
                                        lookaside_namespaced=la_namespaced,
                                        git_excludes=git_excludes,
-                                       results_dir=results_dir
+                                       results_dir=results_dir,
+                                       lookaside_attempts=self.lookaside_attempts,
+                                       lookaside_delay=self.lookaside_delay
                                        )
 
         if self.args.repo_name:
@@ -3087,3 +3089,33 @@ class cliClient(object):
 
     def pre_push_check(self):
         self.cmd.pre_push_check(self.args.ref)
+
+    @property
+    def lookaside_attempts(self):
+        """loads parameter 'lookaside_attempts' from the config file
+        """
+        val = None
+        if self.config.has_option(self.name, 'lookaside_attempts'):
+            val = self.config.get(self.name, 'lookaside_attempts')
+            try:
+                val = int(val)
+            except Exception:
+                self.log.error("Error: The config value 'lookaside_attempts' "
+                               "should be an integer.")
+                val = None
+        return val
+
+    @property
+    def lookaside_delay(self):
+        """loads parameter 'lookaside_delay' from the config file
+        """
+        val = None
+        if self.config.has_option(self.name, 'lookaside_delay'):
+            val = self.config.get(self.name, 'lookaside_delay')
+            try:
+                val = int(val)
+            except Exception:
+                self.log.error("Error: The config value 'lookaside_delay' "
+                               "should be an integer.")
+                val = None
+        return val
-- 
2.43.0