Abstract out update command instead of being embedded in save, added cron

This commit is contained in:
2010-03-02 23:08:19 +00:00
parent b04f943bc5
commit ed258069fd
3 changed files with 29 additions and 3 deletions

27
reddit/cron.py Normal file
View File

@@ -0,0 +1,27 @@
import time
import logging
from django_cron import cronScheduler, Job
from reddit.models import RedditAccount
class UpdateAPIs(Job):
"""
Updates all Reddit API elements in the database
"""
# run every 24 hours
run_every = 86400
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self):
for acc in RedditAccount.objects.all():
acc.api_update()
acc.save()
time.sleep(2)
cronScheduler.register(UpdateAPIs)