Permalink
Browse files

added a method to ListingHandlers to regenerate and a task to call it…

… all
  • Loading branch information...
1 parent e376d34 commit 7fcf8880ac4937ac92dd1a20bf78e0d4f69c4cd9 @HonzaKral HonzaKral committed Apr 11, 2012
View
@@ -287,7 +287,7 @@ def get_keys(cls, category, publishable):
return base_keys + day_keys
@classmethod
- def slide_window(cls, today=None):
+ def regenerate(cls, today=None):
if today is None:
today = date.today()
@@ -1,7 +1,7 @@
-from datetime import datetime
+from datetime import datetime, date
from ella.core.signals import content_published, content_unpublished
-from ella.core.models import Publishable
+from ella.core.models import Publishable, Listing
def generate_publish_signals(now=None):
if now is None:
@@ -19,3 +19,10 @@ def generate_publish_signals(now=None):
content_unpublished.send(sender=p.content_type.model_class(), publishable=p)
qset.update(announced=False)
+def regenerate_listing_handlers(today=None):
+ if today is None:
+ today = date.today()
+
+ Listing.objects._get_listing_handler('default')
+ for lh in Listing.objects._listing_handlers.values():
+ lh.regenerate(today)
@@ -0,0 +1,7 @@
+from django.core.management.base import NoArgsCommand
+
+from ella.core.management import regenerate_listing_handlers
+
+class Command(NoArgsCommand):
+ def handle_noargs(self, **options):
+ regenerate_listing_handlers()
View
@@ -167,6 +167,10 @@ def get_listings_key(self, category=None, children=ListingHandler.NONE, count=10
)
class ListingManager(models.Manager):
+ @classmethod
+ def regenerate(cls, today=None):
+ pass
+
def clean_listings(self):
"""
Method that cleans the Listing model by deleting all listings that are no longer valid.
View
@@ -13,6 +13,7 @@
from celery.task import periodic_task
- from ella.core.management import generate_publish_signals
+ from ella.core.management import generate_publish_signals, regenerate_listing_handlers
periodic_task(run_every=timedelta(hours=1))(generate_publish_signals)
+ periodic_task(run_every=timedelta(hours=3))(regenerate_listing_handlers)
@@ -300,5 +300,5 @@ def test_slide_windows_regenerates_aggregates(self):
self.redis.zadd('sliding:1:20101007', **{'17:1': 8, '17:2': 3, '17:3': 11})
self.redis.zadd('sliding:1:20101001', **{'17:1': 8, '17:2': 3, '17:3': 11})
- SlidingLH.slide_window(date(2010, 10, 10))
+ SlidingLH.regenerate(date(2010, 10, 10))
tools.assert_equals([('17:2', 6.0), ('17:3', 11.0), ('17:1', 27.0)], self.redis.zrange('sliding:1', 0, -1, withscores=True))

0 comments on commit 7fcf888

Please sign in to comment.