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")
def get(self): streams = FeedStream.all().order('-created').fetch(200) self.generate('admin/list.html', { "streams": streams })
def list(self): """List the streams created for this bot""" streams = FeedStream.all().filter('deleted =', False).fetch(100) self.generate('streams.html', {"streams": streams, "title": "Feed Streams", "bot_path": "feeds"})