]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Better handling of HTTP timeouts.
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 25 Mar 2019 09:52:01 +0000 (10:52 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 25 Mar 2019 09:52:01 +0000 (10:52 +0100)
get-forge-modules.yaml
lib/webhooks/get_forge_modules.py
lib/webhooks/module_info.py

index f6cf1ba78c3d1c3e6a8311de04d4032002af3b61..c0cfca557621efe94cb123368cccc17a7a2fd040 100644 (file)
@@ -2,5 +2,5 @@
 
 puppet_env_dir: '/etc/puppetlabs/code/environments'
 forge_uri: 'https://forgeapi.puppet.com/v3/modules'
-http_timeout: 20
+http_timeout: 30
 
index 38de3e5d814da2add38baf202d7a207a4746cad0..23a71eeb7e0186ec7acc77e36db4d67088a0f791 100644 (file)
@@ -217,11 +217,11 @@ class GetForgeModulesApp(BaseHookApp):
                 if module_info:
                     self.forge_modules.append(module_info)
                 modules_done.append(full_name)
-                if not self.verbose:
-                    if module_info:
-                        print('.', end='', flush=True)
-                    else:
-                        print('~', end='', flush=True)
+#                if not self.verbose:
+#                    if module_info:
+#                        print('.', end='', flush=True)
+#                    else:
+#                        print('~', end='', flush=True)
 
         if self.verbose > 1:
             LOG.debug(_(
index 00447c1e8d07fe8badf40b3eff83855ff27aaf00..f1414db400a75419eab83cbef9cd2da710d49972 100644 (file)
@@ -515,21 +515,25 @@ class ModuleInfo(BaseModuleInfo):
             m=full_name, u=url))
 
         session = requests.Session()
-        with warnings.catch_warnings(record=True) as w:
-            warnings.simplefilter("always")
-            response = session.request('GET', url, timeout=http_timeout)
-            if w:
-                warn_class = w[-1].category.__name__
-                warn_msg = '{}: {}'.format(
-                    warn_class, w[-1].message)
-                if warn_class == 'SubjectAltNameWarning':
-                    LOG.debug(warn_msg)
-                else:
-                    LOG.warn(warn_msg)
-
-        LOG.debug("Got status code: {}.".format(response.status_code))
+        try:
+            with warnings.catch_warnings(record=True) as w:
+                warnings.simplefilter("always")
+                response = session.request('GET', url, timeout=http_timeout)
+                if w:
+                    warn_class = w[-1].category.__name__
+                    warn_msg = '{}: {}'.format(
+                        warn_class, w[-1].message)
+                    if warn_class == 'SubjectAltNameWarning':
+                        LOG.debug(warn_msg)
+                    else:
+                        LOG.warn(warn_msg)
+        except requests.exceptions.ReadTimeout as e:
+            LOG.error("{c}: {e}".format(c=e.__class__.__name__, e=e))
+            return None
+
+        LOG.debug(_("Got status code: {}.").format(response.status_code))
         if not response.ok:
-            LOG.debug("Did not found module {} on Puppet forge.".format(full_name))
+            LOG.debug(_("Did not found module {} on Puppet forge.").format(full_name))
             return None
 
         if not response.text: