Exemplo n.º 1
0
    def get_route(self, route_tag, fields=None):

        route = yield self.get_route_from_cache(route_tag)

        if route is None:
            # Use service and cache result
            self.support.notify_debug(
                '[Agency] route {0}/{1} not found in cache. Using service'.
                format(self.agency_tag, route_tag))
            try:
                with self.breaker_set.context('next_bus'):
                    nextbus_service = NextBusService(support=self.support)
                    route = yield nextbus_service.get_route(
                        self.agency_tag, route_tag)
            except breaker.CircuitOpenError:
                self.support.notify_debug(
                    '[Agency] Call to service provider failed. Circuit is open'
                )
                raise exceptions.ExternalProviderUnavailableTemporarily(
                    'NextBus')

            yield self.store_route_in_cache(route_tag, route)

        filtered_route = {}
        if fields:
            for field in fields:
                filtered_route[field] = route.get(field)
            route = filtered_route

        raise gen.Return(route)
Exemplo n.º 2
0
    def get_route_vehicles(self, agency_tag, route_tag, last_time):

        vehicles = yield self.get_route_vehicles_from_cache(
            agency_tag, route_tag)

        if vehicles is None:
            # Use service and cache result
            self.support.notify_debug(
                'vehicles for route {0}/{1} not found in cache. Using service'.
                format(agency_tag, route_tag))
            try:
                with self.breaker_set.context('next_bus'):
                    nextbus_service = NextBusService(support=self.support)
                    vehicles = yield nextbus_service.get_route_vehicles(
                        agency_tag, route_tag, last_time)
            except breaker.CircuitOpenError:
                self.support.notify_debug(
                    '[Agency] Call to service provider failed. Circuit is open'
                )
                raise exceptions.ExternalProviderUnavailableTemporarily(
                    'NextBus')

            yield self.store_route_vehicles_in_cache(agency_tag, route_tag,
                                                     vehicles)

        raise gen.Return(vehicles)
Exemplo n.º 3
0
    def get_routes(self, criteria):

        routes = yield self.get_routes_from_cache()

        if routes is None:
            # Use service and cache result
            self.support.notify_debug(
                '[Agency] routes for {0} not found in cache. Using service'.
                format(self.agency_tag))
            try:
                with self.breaker_set.context('next_bus'):
                    nextbus_service = NextBusService(support=self.support)
                    routes = yield nextbus_service.get_routes(self.agency_tag)
            except breaker.CircuitOpenError:
                self.support.notify_debug(
                    '[Agency] Call to service provider failed. Circuit is open'
                )
                raise exceptions.ExternalProviderUnavailableTemporarily(
                    'NextBus')

            yield self.store_routes_in_cache(routes)

        not_running_at = criteria.get(api.CRITERIA_NOT_RUNNING_AT)

        if not_running_at:
            routes = yield self.get_routes_not_running_at(
                routes, not_running_at)

        raise gen.Return(routes)
Exemplo n.º 4
0
    def get_route_predictions(self, agency_tag, route_tag, stop_tag):

        predictions = yield self.get_predictions_from_cache(
            agency_tag, route_tag, stop_tag)

        if predictions is None:
            # Use service and cache result
            self.support.notify_debug(
                'predictions for route {0}/{1} and stop {2} not found in cache. '
                'Using service'.format(agency_tag, route_tag, stop_tag))
            try:
                with self.breaker_set.context('next_bus'):
                    nextbus_service = NextBusService(support=self.support)
                    predictions = yield nextbus_service.get_route_predictions(
                        agency_tag, route_tag, stop_tag)
            except breaker.CircuitOpenError:
                self.support.notify_debug(
                    '[Agency] Call to service provider failed. Circuit is open'
                )
                raise exceptions.ExternalProviderUnavailableTemporarily(
                    'NextBus')

            yield self.store_predictions_in_cache(agency_tag, route_tag,
                                                  stop_tag, predictions)

        raise gen.Return(predictions)
Exemplo n.º 5
0
    def get_agencies(self):

        agencies = yield self.get_agencies_from_cache()

        if agencies is None:
            # Use service and cache result
            self.support.notify_debug(
                'agencies not found in cache. Using service')

            try:
                with self.breaker_set.context('next_bus'):
                    nextbus_service = NextBusService(support=self.support)
                    agencies = yield nextbus_service.get_agencies()
            except breaker.CircuitOpenError:
                self.support.notify_debug(
                    '[Service] Call to service provider failed. Circuit is open'
                )
                raise exceptions.ExternalProviderUnavailableTemporarily(
                    'NextBus')

            yield self.store_agencies_in_cache(agencies)

        raise gen.Return(agencies)
Exemplo n.º 6
0
 def some_func():
     self.actual_tries += 1
     if self.actual_tries < expected_tries:
         raise exceptions.ExternalProviderUnavailableTemporarily(
             "some error")
Exemplo n.º 7
0
 def test_ExternalProviderUnavailableTemporarily(self):
     try:
         raise exceptions.ExternalProviderUnavailableTemporarily(
             "Testing ExternalProviderUnavailableTemporarily")
     except exceptions.ExternalProviderUnavailableTemporarily:
         pass