Skip to content

Commit

Permalink
regularly schedule file count updates for #377
Browse files Browse the repository at this point in the history
  • Loading branch information
btbonval committed Jan 24, 2015
1 parent 5be27c8 commit 321c9fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 2 additions & 11 deletions karmaworld/apps/courses/management/commands/fix_note_counts.py
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions karmaworld/apps/courses/tasks.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions karmaworld/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
'task': 'get_extract_keywords_results',
'schedule': timedelta(minutes=20),
},
'update-scoreboard': {
'task': 'fix_note_counts',
'schedule': timedelta(days=1),
},
}

CELERY_TIMEZONE = 'UTC'
Expand Down

0 comments on commit 321c9fd

Please sign in to comment.