Ejemplo n.º 1
0
  def post(self):
    stream = FeedStream.get(db.Key(self.request.POST.get("key")))
    if stream is None:
      logging.warn("feedstream not found for subscription request")
      self.response.out.write("feedstream not found for subscription request")
      self.error(404)
      return

    feed = feedparser.parse(stream.url)
    if hasattr(feed, 'feed') and hasattr(feed.feed, 'links'):
      hub_url = find_feed_url('hub', feed.feed.links)
      if hub_url is None:
        logging.info("no hub found for: %s" % stream.url)
        self.response.out.write('no hub found')
        return
      else:
        logging.info("sending pshb subscription request for: %s" % stream.url)
        stream.pshb_hub_url = hub_url
        stream.put()
        self.subscribe_to_topic(stream, hub_url)
        self.response.out.write('sent subscription request')
        return

    logging.warn('could not parse feed unable to initiate subscription')
    self.response.out.write('could not parse feed unable to initiate subscription')
    self.error(400)
Ejemplo n.º 2
0
  def post(self):
    # allow single feed to be updated
    key = self.request.get("key")
    if key is not None and len(key) > 0:
      feed = FeedStream.get(db.Key(key))
      if feed is None:
        self.response.out.write("no feed to update")
        return
      self.update_feed(feed)
      self.response.out.write("feed updated")
      return

    # no key do the recursive polling
    is_enabled = FeedPollerConfig.get_instance().is_enabled
    if is_enabled is None or is_enabled == False:
      logging.info("feed poller not enabled shutting down")
      self.response.out.write("feed poller not enabled shutting down")
      return

    # Get the stalest feed
    feed = FeedStream.all().filter('deleted = ', False).order('last_polled').get()

    # Check how stale the stalest feed is, if it's been updated in the
    # last 10 minutes, we should take a break
    max_age = datetime.utcnow() - timedelta(minutes=10)
    if feed.last_polled >= max_age:
      if not memcache.set("feed_poller_running", False):
        logging.error("memcache set failed")
      logging.info("putting feed poller to sleep")
      self.response.out.write("putting feed poller to sleep")
      return

    # go get the feed
    try:
      self.update_feed(feed)
    except:
      logging.warn("Update Failed for feed with stream_id %s and url: %s" % (feed.stream_id, feed.url))
      logging.error(sys.exc_info()[0])
      try:
        feed.last_polled = datetime.utcnow()
        feed.has_error = True
        feed.put()
      except:
        logging.warn("failed to save feed error")
    
    # Queue the next feed
    task = taskqueue.Task(url='/feedpoller/tasks/poll', params={}).add(queue_name="feed-poller")
    self.response.out.write("feed updated")