From 321c9fd8be8eb3776ee56f628d2918d689ac4e2c Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 9 Jan 2015 17:33:10 -0500 Subject: [PATCH] regularly schedule file count updates for #377 --- .../management/commands/fix_note_counts.py | 13 ++---------- karmaworld/apps/courses/tasks.py | 21 +++++++++++++++++++ karmaworld/settings/prod.py | 4 ++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 karmaworld/apps/courses/tasks.py diff --git a/karmaworld/apps/courses/management/commands/fix_note_counts.py b/karmaworld/apps/courses/management/commands/fix_note_counts.py index 1b896ab..3197fd2 100644 --- a/karmaworld/apps/courses/management/commands/fix_note_counts.py +++ b/karmaworld/apps/courses/management/commands/fix_note_counts.py @@ -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 index 0000000..1674bff --- /dev/null +++ b/karmaworld/apps/courses/tasks.py @@ -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) diff --git a/karmaworld/settings/prod.py b/karmaworld/settings/prod.py index b83cb9b..4329cdc 100644 --- a/karmaworld/settings/prod.py +++ b/karmaworld/settings/prod.py @@ -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' -- 2.25.1