Esempio n. 1
0
def update_all_feeds(interval_id):
    """Update all feeds for a specific interval"""
    if request.headers.get('X-Appengine-Cron') != 'true':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    feeds = Feed.for_interval(interval_id)

    success = 0
    more = True
    cursor = None
    futures = []
    while more:
        feeds_to_fetch, cursor, more = yield feeds.fetch_page_async(100, start_cursor=cursor)
        keys = ','.join([x.key.urlsafe() for x in feeds_to_fetch])
        if not keys:
            continue

        futures.append(Queue('poll').add_async(Task(url=url_for('tq_feed_poll'), method='POST', params={'keys': keys})))
        success += 1

    for future in futures:
        yield future

    logger.info('queued poll for %d feeds at interval_id=%s', success, interval_id)

    raise ndb.Return(jsonify(status='ok'))
Esempio n. 2
0
def update_all_feeds(interval_id):
    """Update all feeds for a specific interval"""
    if request.headers.get('X-Appengine-Cron') != 'true':
        return jsonify_error(message='Not a cron call')

    feeds = Feed.for_interval(interval_id)

    for feed in feeds:
        feed.prepare_request()

    errors = 0
    success = 0
    for feed in feeds:
        try:
            Entry.update_for_feed(feed, publish=True)
            success += 1
        except FetchException, e:
            errors += 1
            pass
        except Exception, e:
            errors += 1
            logger.exception('Failed to update feed:%s' % (feed.feed_url, ))