def run(self, *args, **options): """Loop forever, and update feeds. # TODO: take options from the command line that we pass on to ``update_feed``, changing the parsing behavior (addins can use the options to adjust their behavior). """ # Code below fails in sqlite because we can't update a row # while it is still part of queryset, IIRC: #feed = db.store.get_next_feed() #while feed: # update_feed(feed) # feed = db.store.get_next_feed() callback = self.callback do_return = lambda: callback and callback(counter) counter = 0 while True: feeds = db.store.find(db.models.Feed) for i in xrange(0, feeds.count()): # XXX: only do this in sqlite feed = feeds[i] counter += 1 parse.update_feed(feed) if do_return() or self.stop_requested: return if do_return() or self.stop_requested: return if self.once: return
def run(self): while not self.stop_requested: try: # Since Queue itself just uses an infinite loop to # implement it's blocking feature, we sort of don't # need to bother specifying a timeout. We'd rather # use the opportunity to check ``stop_requested`` # more often. feed = self.queue.get(timeout=0.1) try: # We need to be careful here, there's really no # guarantee that the feed still exists. parse.update_feed(feed) except Exception, e: # TODO: do not catch all exceptions self.log.error('Error handling queued feed: %s' % e) except Queue.Empty: time.sleep(DEFAULT_LOOP_SLEEP)