From 298c99c6a68d3bd92c6934b53c7f0d083dba64f7 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 24 May 2011 11:38:52 +0100 Subject: [PATCH] Added Reddit recurring tasks to update the details --- app/reddit/tasks.py | 35 +++++++++++++++++++++++++++++++++++ app/settings.py | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/app/reddit/tasks.py b/app/reddit/tasks.py index b79ce34..6b86c45 100644 --- a/app/reddit/tasks.py +++ b/app/reddit/tasks.py @@ -46,3 +46,38 @@ def process_validations(): except LoginError, exc: logger.error("Error logging into Reddit") return + + +@task(ignore_result=True) +def update_account(username): + + logger = process_validations.get_logger() + + try: + acc = RedditAccount.objects.get(pk=username) + except RedditAccount.DoesNotExist: + pass + else: + acc.api_update + acc.save() + + +@task(ignore_result=True, expires=120) +def queue_account_updates(update_delay=604800, batch_size=50): + """ + Updates all Reddit accounts in the system + """ + + log = queue_account_updates.get_logger() + # Update all the eve accounts and related corps + delta = timedelta(seconds=update_delay) + log.info("Updating Accounts older than %s" % (datetime.now() - delta)) + accounts = RedditAccount.objects.filter(last_updated_lt=(datetime.now() - delta)) + log.info("%s account(s) to update" % accounts.count()) + for acc in accounts: + log.debug("Queueing Account %s for update" % acc.username) + if not acc.user: + acc.delete() + continue + update_account.delay(username=acc.pk) + diff --git a/app/settings.py b/app/settings.py index 5dc42f7..11d5f9e 100755 --- a/app/settings.py +++ b/app/settings.py @@ -197,6 +197,10 @@ CELERYBEAT_SCHEDULE = { "task": "hr.tasks.blacklist_check", "schedule": timedelta(days=1), }, + "reddit-update": { + "task": "reddit.tasks.queue_account_updates", + "schedule": timedelta(minutes=15), + } } CELERY_SEND_TASK_ERROR_EMAILS = True @@ -204,6 +208,7 @@ CELERY_RESULT_BACKEND = "amqp" CELERY_DISABLE_RATE_LIMITS = True CELERYD_PREFETCH_MULTIPLIER = 128 CELERY_ALWAYS_EAGER = DEBUG +CELERY_EAGER_PROPAGATES_EXCEPTIONS = DEBUG # Load the Celery tasks djcelery.setup_loader()