Пример #1
0
    def post(self):
        raw_proto = _get_gtfs_rt(flask.globals.request)

        from kirin import gtfs_realtime_pb2
        # create a raw gtfs-rt obj, save the raw protobuf into the db
        proto = gtfs_realtime_pb2.FeedMessage()
        try:
            proto.ParseFromString(raw_proto)
        except DecodeError:
            raise InvalidArguments('invalid protobuf')

        proto.ParseFromString(raw_proto)
        model_maker.handle(proto, self.navitia_wrapper, self.contributor)

        return 'OK', 200
Пример #2
0
def gtfs_poller(self, config):
    func_name = 'gtfs_poller'
    logger = logging.LoggerAdapter(logging.getLogger(__name__), extra={'contributor': config['contributor']})
    logger.debug('polling of %s', config['feed_url'])

    contributor = config['contributor']
    lock_name = make_kirin_lock_name(func_name, contributor)
    with get_lock(logger, lock_name, app.config['REDIS_LOCK_TIMEOUT_POLLER']) as locked:
        if not locked:
            new_relic.ignore_transaction()
            return

        # We do a HEAD request at the very beginning of polling and we compare it with the previous one to check if
        # the gtfs-rt is changed.
        # If the HEAD request or Redis get/set fail, we just ignore this part and do the polling anyway
        if not _is_newer(config):
            new_relic.ignore_transaction()
            manage_db_no_new(connector='gtfs-rt', contributor=contributor)
            return

        try:
            response = requests.get(config['feed_url'], timeout=config.get('timeout', 1))
            response.raise_for_status()

        except Exception as e:
            manage_db_error(data='', connector='gtfs-rt', contributor=contributor,
                            status='KO', error='Http Error')
            logger.debug(str(e))
            return

        nav = navitia_wrapper.Navitia(url=config['navitia_url'],
                                      token=config['token'],
                                      timeout=5,
                                      cache=redis,
                                      query_timeout=app.config.get('NAVITIA_QUERY_CACHE_TIMEOUT', 600),
                                      pubdate_timeout=app.config.get('NAVITIA_PUBDATE_CACHE_TIMEOUT', 600))\
            .instance(config['coverage'])

        proto = gtfs_realtime_pb2.FeedMessage()
        try:
            proto.ParseFromString(response.content)
        except DecodeError:
            manage_db_error(proto, 'gtfs-rt', contributor=contributor, status='KO', error='Decode Error')
            logger.debug('invalid protobuf')
        else:
            model_maker.handle(proto, nav, contributor)
            logger.info('%s for %s is finished', func_name, contributor)
Пример #3
0
def gtfs_poller(self, config):
    logger = logging.LoggerAdapter(
        logging.getLogger(__name__),
        extra={'contributor': config['contributor']})
    logger.debug('polling of %s', config['feed_url'])
    response = requests.get(config['feed_url'],
                            timeout=config.get('timeout', 1))
    response.raise_for_status()

    nav = navitia_wrapper.Navitia(url=config['navitia_url'], token=config['token'])\
                         .instance(config['coverage'])
    nav.timeout = 5

    proto = gtfs_realtime_pb2.FeedMessage()
    proto.ParseFromString(response.content)
    model_maker.handle(proto, nav, config['contributor'])
    logger.debug('gtfsrt polling finished')
Пример #4
0
    def post(self):
        raw_proto = _get_gtfs_rt(flask.globals.request)

        from kirin import gtfs_realtime_pb2
        # create a raw gtfs-rt obj, save the raw protobuf into the db
        proto = gtfs_realtime_pb2.FeedMessage()
        try:
            proto.ParseFromString(raw_proto)
        except DecodeError:
            #We save the non-decodable flux gtfs-rt
            manage_db_error(proto,
                            'gtfs-rt',
                            contributor=self.contributor,
                            status='KO',
                            error='Decode Error')
            raise InvalidArguments('invalid protobuf')
        else:
            model_maker.handle(proto, self.navitia_wrapper, self.contributor)
            return 'OK', 200