regularly schedule file count updates for #377
authorBryan <btbonval@gmail.com>
Fri, 9 Jan 2015 22:33:10 +0000 (17:33 -0500)
committerBryan <btbonval@gmail.com>
Sat, 24 Jan 2015 07:40:34 +0000 (02:40 -0500)
karmaworld/apps/courses/management/commands/fix_note_counts.py
karmaworld/apps/courses/tasks.py [new file with mode: 0644]
karmaworld/settings/prod.py

index 1b896abe3f61f89a0ea33d495ce54322b4365357..3197fd2a4b5877b2686ce11dca50a5f1b58b9190 100644 (file)
@@ -1,18 +1,9 @@
 from django.core.management.base import BaseCommand
-from karmaworld.apps.notes.models import *
-from karmaworld.apps.courses.models import *
+from karmaworld.apps.courses.tasks import fix_note_counts
 
 class Command(BaseCommand):
     help = """Set the field file_count on every Course and School
             to the correct value."""
 
     def handle(self, *args, **kwargs):
-        for c in Course.objects.all():
-            c.update_note_count()
-            print "Updated course {c}".format(c=c)
-
-        for s in School.objects.all():
-            s.update_note_count()
-            print "Updated school {s}".format(s=s)
-
-
+        fix_note_counts()
diff --git a/karmaworld/apps/courses/tasks.py b/karmaworld/apps/courses/tasks.py
new file mode 100644 (file)
index 0000000..1674bff
--- /dev/null
@@ -0,0 +1,21 @@
+from karmaworld.apps.courses.models import Course
+from karmaworld.apps.courses.models import School
+
+from celery import task
+from celery.utils.log import get_task_logger
+
+logger = get_task_logger(__name__)
+
+@task(name="fix_note_counts")
+def fix_note_counts():
+    """
+    Set the field file_count on every Course and School to the correct value.
+    """
+
+    for c in Course.objects.all():
+        c.update_note_count()
+        print "Updated course {c}".format(c=c)
+
+    for s in School.objects.all():
+        s.update_note_count()
+        print "Updated school {s}".format(s=s)
index b83cb9bc61519d2f8f7c1a21e6736232d7268ffa..4329cdca6a9c1663f7f01f8d30af67d780109ee0 100644 (file)
@@ -93,6 +93,10 @@ CELERYBEAT_SCHEDULE = {
         'task': 'get_extract_keywords_results',
         'schedule': timedelta(minutes=20),
     },
+    'update-scoreboard': {
+        'task': 'fix_note_counts',
+        'schedule': timedelta(days=1),
+    },
 }
 
 CELERY_TIMEZONE = 'UTC'