Example #1
0
 def service_caller(self, method, url, headers, data=None, params=None):
     try:
         kwargs = {
             "timeout": self.timeout,
             "verify": self.verify_certificate,
             "headers": headers
         }
         if data:
             kwargs.update({"data": data})
         if params:
             kwargs.update({'params': params})
         response = self.breaker.call(method, url, **kwargs)
         if not response or response.status_code != 200:
             logging.getLogger(__name__).error(
                 'cykleo, Invalid response, status_code: {}'.format(
                     response.status_code))
             raise BssProxyError('non 200 response')
         return response
     except pybreaker.CircuitBreakerError as e:
         logging.getLogger(__name__).error(
             'cykleo service dead (error: {})'.format(e))
         raise BssProxyError('circuit breaker open')
     except requests.Timeout as t:
         logging.getLogger(__name__).error(
             'cykleo service timeout (error: {})'.format(t))
         raise BssProxyError('timeout')
     except Exception as e:
         logging.getLogger(__name__).exception('cykleo error : {}'.format(
             str(e)))
         raise BssProxyError(str(e))
Example #2
0
    def _get_informations(self, poi):
        logging.debug('building stands')
        try:
            all_stands = self.breaker.call(self._get_all_stands)
            ref = poi.get('properties', {}).get('ref')
            if not ref:
                return Stands(0, 0, StandsStatus.unavailable)
            stands = all_stands.get(ref.lstrip('0'))
            if stands:
                if stands.status != 'open':
                    stands.available_bikes = 0
                    stands.available_places = 0
                    stands.total_stands = 0

                return stands
        except pybreaker.CircuitBreakerError as e:
            logging.getLogger(__name__).error('atos service dead (error: {})'.format(e))
            raise BssProxyError('circuit breaker open')
        except requests.Timeout as t:
            logging.getLogger(__name__).error('atos service timeout (error: {})'.format(t))
            raise BssProxyError('timeout')
        except Exception as e:
            logging.getLogger(__name__).exception('cykleo error : {}'.format(str(e)))
            raise BssProxyError(str(e))

        return Stands(0, 0, StandsStatus.unavailable)
Example #3
0
 def _call_webservice(self):
     try:
         data = self.breaker.call(requests.get,
                                  self.WS_URL_TEMPLATE.format(
                                      self.contract, self.api_key),
                                  timeout=self.timeout)
         stands = {}
         for s in data.json():
             stands[str(s['number'])] = s
         return stands
     except pybreaker.CircuitBreakerError as e:
         logging.getLogger(__name__).error(
             'JCDecaux service dead (error: {})'.format(e))
         raise BssProxyError('circuit breaker open')
     except requests.Timeout as t:
         logging.getLogger(__name__).error(
             'JCDecaux service timeout (error: {})'.format(t))
         raise BssProxyError('timeout')
     except Exception as e:
         logging.getLogger(__name__).exception('JCDecaux error : {}'.format(
             str(e)))
         raise BssProxyError(str(e))