mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-22 22:29:34 +00:00
Abstract out update command instead of being embedded in save, added cron
This commit is contained in:
27
reddit/cron.py
Normal file
27
reddit/cron.py
Normal 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)
|
||||
Reference in New Issue
Block a user