def handle(self, *args, **options): if options['daemonize']: daemonize() settings.LOG_TO_STREAM = True r = redis.Redis(connection_pool=settings.REDIS_FEED_POOL) if options['initialize']: feeds = Feed.objects.filter(num_subscribers__gte=1).order_by('?') print 'Query feeds done with num of feeds', len(feeds) r.ltrim('freeze_feeds', 1, 0) pipeline = r.pipeline() for feed in feeds: pipeline.rpush('freeze_feeds', feed.pk) pipeline.execute() print 'Initialize freeze_feeds done' feed_id = r.lpop('freeze_feeds') while feed_id: try: frozen_num = MStory.freeze_feed(int(feed_id)) if frozen_num > 0: r.rpush('freeze_feeds', feed_id) except Exception, e: logging.error(str(e)+\ traceback.format_exc()+'\n'+\ 'Error from: freeze_feeds\n') feed_id = r.lpop('freeze_feeds')
def handle(self, *args, **options): if options['daemonize']: daemonize() settings.LOG_TO_STREAM = True r = redis.Redis(connection_pool=settings.REDIS_FEED_POOL) if options['initialize']: feeds = Feed.objects.filter(num_subscribers__gte=1).order_by('?') print 'Query feeds done with num of feeds',len(feeds) r.ltrim('freeze_feeds',1,0) pipeline = r.pipeline() for feed in feeds: pipeline.rpush('freeze_feeds',feed.pk) pipeline.execute() print 'Initialize freeze_feeds done' feed_id = r.lpop('freeze_feeds') while feed_id: try: frozen_num = MStory.freeze_feed(int(feed_id)) if frozen_num > 0: r.rpush('freeze_feeds',feed_id) except Exception, e: logging.error(str(e)+\ traceback.format_exc()+'\n'+\ 'Error from: freeze_feeds\n') feed_id = r.lpop('freeze_feeds')
def run(self,feed_pk,**kwargs): from apps.rss_feeds.models import MStory MStory.freeze_feed(feed_pk) logging.info('---> ~FYProcess freeze feed %d done!~FW'%feed_pk)