Skip to content

Commit

Permalink
Merge pull request #371 from soar-telescope/add_timeout_to_github
Browse files Browse the repository at this point in the history
Added timeout to github request and handled ConnectionError exception
  • Loading branch information
simontorres authored Aug 17, 2023
2 parents a2b34f7 + cde4da8 commit 1a90b76
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/change_history.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Change History
##############

.. _v1.3.7:

V1.3.7 17-08-2023
^^^^^^^^^^^^^^^^^

- Updated documentation theme to allow dark mode
- Removed python 3.6 and 3.8 from testing and added 3.9 and 3.10
- Unfixed numpy version
- Removed testing with conda on github action because it only added complexity
- Added 3 seconds timeout to request to github to validate version and check if running version is latest
- Added correct exception handler in case the http request timed out.


.. _v1.3.6:

V1.3.6 25-03-2022
Expand Down
2 changes: 1 addition & 1 deletion goodman_pipeline/core/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_last(github_api_token='GITHUB_ACCESS_TOKEN'):
except KeyError:
headers = {}

response = requests.get(API_URL, headers=headers)
response = requests.get(API_URL, headers=headers, timeout=3)

if response.status_code != 200: # pragma: no cover
raise ConnectionRefusedError('Number of tests reached maximum for now.')
Expand Down
7 changes: 6 additions & 1 deletion goodman_pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
import time

import requests
from astropy.utils import iers
iers.Conf.iers_auto_url.set('ftp://cddis.gsfc.nasa.gov/pub/products/iers/finals2000A.all')
from astroplan import Observer
Expand Down Expand Up @@ -2958,7 +2959,11 @@ def setup_logging(debug=False, generic=False): # pragma: no cover
log.info("Latest Release: {:s}".format(latest_release))
except ConnectionRefusedError:
log.error('Unauthorized GitHub API Access reached maximum')
log.info("Current Version: {:s}".format(__version__))
log.info(f"Current Version: {__version__}")
except requests.exceptions.ConnectionError:
log.warning("Unable to validate latest version. "
"The connection timed out or was not possible to establish")
log.info(f"Current Version: {__version__}")


def trace(ccd,
Expand Down
17 changes: 14 additions & 3 deletions goodman_pipeline/core/tests/test_check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import unittest

import requests

from goodman_pipeline.core import check_version

__version__ = __import__('goodman_pipeline').__version__
Expand All @@ -18,6 +20,8 @@ def test_get_last(self):
# self.assertEqual(v, __version__)
except ConnectionRefusedError: # pragma: no cover
pass
except requests.exceptions.ConnectionError: # pragma: no cover
pass

def test_get_last_no_token(self):
try:
Expand All @@ -26,14 +30,19 @@ def test_get_last_no_token(self):
# self.assertEqual(v, __version__)
except ConnectionRefusedError: # pragma: no cover
pass
except requests.exceptions.ConnectionError: # pragma: no cover
pass
except KeyError: # pragma: no cover
pass

def test_get_last_token(self):
os.environ['FAKETOKEN'] = 'ThisIsNotARealToken'
self.assertRaises(ConnectionRefusedError,
check_version.get_last,
'FAKETOKEN')
try:
self.assertRaises(ConnectionRefusedError,
check_version.get_last,
'FAKETOKEN')
except requests.exceptions.ConnectionError:
pass


def test_am_i_updated(self):
Expand All @@ -42,3 +51,5 @@ def test_am_i_updated(self):
self.assertFalse(check_version.am_i_updated('v0.0.0'))
except ConnectionRefusedError: # pragma: no cover
pass
except requests.exceptions.ConnectionError: # pragma: no cover
pass
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ install_requires =
ccdproc
astroplan
# version should be PEP440 compatible (http://www.python.org/dev/peps/pep-0440)
version = 1.3.6
version = 1.3.7

0 comments on commit 1a90b76

Please sign in to comment.