Using secondary mongos for feed fetch histories.

This commit is contained in:
Samuel Clay 2013-03-25 09:00:56 -07:00
parent a4238d20b3
commit c146f17af6

View file

@ -1,6 +1,7 @@
import datetime
import mongoengine as mongo
import urllib2
import pymongo
from django.conf import settings
from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory, MFeedPushHistory
from apps.social.models import MSharedStory
@ -74,17 +75,21 @@ class MStatistics(mongo.Document):
last_day = datetime.datetime.now() - datetime.timedelta(hours=24)
last_month = datetime.datetime.now() - datetime.timedelta(days=30)
feeds_fetched = MFeedFetchHistory.objects.filter(fetch_date__gte=last_day).count()
feeds_fetched = MFeedFetchHistory.objects.filter(fetch_date__gte=last_day)\
.read_preference(pymongo.ReadPreference.SECONDARY).count()
cls.objects(key='feeds_fetched').update_one(upsert=True, set__key='feeds_fetched', set__value=feeds_fetched)
pages_fetched = MPageFetchHistory.objects.filter(fetch_date__gte=last_day).count()
pages_fetched = MPageFetchHistory.objects.filter(fetch_date__gte=last_day)\
.read_preference(pymongo.ReadPreference.SECONDARY).count()
cls.objects(key='pages_fetched').update_one(upsert=True, set__key='pages_fetched', set__value=pages_fetched)
feeds_pushed = MFeedPushHistory.objects.filter(push_date__gte=last_day).count()
feeds_pushed = MFeedPushHistory.objects.filter(push_date__gte=last_day)\
.read_preference(pymongo.ReadPreference.SECONDARY).count()
cls.objects(key='feeds_pushed').update_one(upsert=True, set__key='feeds_pushed', set__value=feeds_pushed)
from utils.feed_functions import timelimit, TimeoutError
@timelimit(60)
def delete_old_history():
print "Deleting old history."
print "Deleting old history. Nope."
return
feed_fetch_last_day = MFeedFetchHistory.objects(fetch_date__lt=last_day, status_code__in=[200, 304])
page_fetch_last_day = MPageFetchHistory.objects(fetch_date__lt=last_day, status_code__in=[200, 304])
feed_fetch_last_month = MFeedFetchHistory.objects(fetch_date__lt=last_month)