def get(self):
   config = FeedPollerConfig.get_instance() 
   if config.is_enabled is None or config.is_enabled == False:
     config.is_enabled = True
   else:
     config.is_enabled = False
   db.put(config)
   self.response.out.write("enabled %s" % FeedPollerConfig.get_instance().is_enabled)
  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")
Beispiel #3
0
  def cron(self):
    """Wake up the feed poller"""
    is_enabled = FeedPollerConfig.get_instance().is_enabled 
    if is_enabled is None or is_enabled == False:
      logging.debug("feed poller not enabled")
      self.response.out.write("feed poller not enabled")
      return

    is_running = memcache.get("feed_poller_running")
    if is_running is not None and is_running == True:
      logging.debug("feed poller already running")
      self.response.out.write("feed poller already running")
      return

    # Queue the poller    
    if not memcache.set("feed_poller_running", True):
      logging.error("memcache set failed")
    task = taskqueue.Task(url='/feedpoller/tasks/poll', params={}).add(queue_name="feed-poller")

    logging.debug("woke up the feed poller")
    self.response.out.write("woke up the feed poller")