Migrated the final cronjobs over to tasks

This commit is contained in:
2010-11-10 12:15:43 +00:00
parent f7657a7325
commit db28b3902a
8 changed files with 22 additions and 146 deletions

View File

@@ -1,6 +0,0 @@
ROOT=/home/matalok/auth/auth
@daily $ROOT/run-cron.py reddit.cron UpdateAPIs > $ROOT/logs/redditapi-update.log 2>&1
*/5 * * * * $ROOT/run-cron.py eve_api.cron UpdateAPIs > $ROOT/logs/eveapi-update.log 2>&1
0 */6 * * * $ROOT/run-cron.py eve_api.cron AllianceUpdate > $ROOT/logs/alliance-update.log 2>&1
@daily $ROOT/run-cron.py eve_proxy.cron ClearStaleCache > $ROOT/logs/cache-clear.log 2>&1

View File

@@ -1,25 +0,0 @@
import logging
import datetime
from eve_api.models.api_player import EVEAccount, EVEPlayerCorporation, EVEPlayerCharacter
import eve_api.api_puller.accounts
from eve_api.api_puller.alliances import __start_full_import as alliance_import
from eve_api.api_puller.corp_management import pull_corp_members
from eve_api.api_exceptions import APIAuthException, APINoUserIDException
from eve_api.app_defines import *
from eve_api.tasks import *
class AllianceUpdate():
"""
Pulls the AllianceList.xml.aspx and updates the alliance objects
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self, args):
alliance_import()

View File

@@ -60,6 +60,12 @@ def import_apikey(api_userid, api_key, user=None, force_cache=False):
return acc
@task(ignore_result=True, rate_limit='10/d')
def import_alliance_details():
from eve_api.api_puller.alliances import __start_full_import as alliance_import
alliance_import()
@task(ignore_result=True, rate_limit='5/m')
def import_corp_members(api_userid, api_key, character_id):
pull_corp_members(api_key, api_userid, character_id)

View File

@@ -1,37 +0,0 @@
import logging
from datetime import datetime
from eve_proxy.models import CachedDocument
class ClearStaleCache():
"""
Clears out any stale cache entries
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self, args):
objs = CachedDocument.objects.filter(cached_until__lt=datetime.utcnow())
self._logger.info('Removing %s stale cache documents' % objs.count())
objs.delete()
class FlushCache():
"""
Flushes the entire cache
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
def job(self, args):
objs = CachedDocument.objects.all()
self._logger.info('Removing %s stale cache documents' % objs.count())
objs.delete()

12
eve_proxy/tasks.py Normal file
View File

@@ -0,0 +1,12 @@
import logging
from datetime import datetime, timedelta
from celery.decorators import task
from eve_proxy.models import CachedDocument
@task(ignore_result=True)
def clear_stale_cache(cache_extension=0):
log = clear_stale_cache.get_logger()
time = datetime.utcnow() - timedelta(seconds=cache_extension)
objs = CachedDocument.objects.filter(cached_until__lt=datetime.utcnow()).delete()
self.log.info('Removed %s stale cache documents' % objs.count())

View File

@@ -1,35 +0,0 @@
import time
import datetime
import logging
import settings
from reddit.models import RedditAccount
from reddit.api import Inbox
class UpdateAPIs():
"""
Updates all Reddit API elements in the database
"""
@property
def _logger(self):
if not hasattr(self, '__logger'):
self.__logger = logging.getLogger(__name__)
return self.__logger
last_update_delay = 604800
def job(self, args):
delta = datetime.timedelta(seconds=self.last_update_delay)
self._logger.debug("Updating accounts older than %s" % (datetime.datetime.now() - delta))
for acc in RedditAccount.objects.filter(last_update__lt=(datetime.datetime.now() - delta)):
self._logger.info("Updating %s" % acc.username)
try:
acc.api_update()
except RedditAccount.DoesNotExist:
acc.delete()
else:
acc.save()
time.sleep(.5)

View File

@@ -1,42 +0,0 @@
#!/usr/bin/env python
"""Executes a Django cronjob"""
import os
# Activate the virtualenv
path = os.path.dirname(os.path.realpath( __file__ ))
os.chdir(path)
activate_this = os.path.join(path, 'env/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
from django.core.management import setup_environ
import settings
setup_environ(settings)
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('runcron')
try:
mod = __import__(sys.argv[1])
except ImportError:
raise Exception('Error creating service')
for i in sys.argv[1].split(".")[1:]:
mod = getattr(mod, i)
cron_class = getattr(mod, sys.argv[2])()
log.info("Starting Job %s in %s" % (sys.argv[2], sys.argv[1]))
try:
if len(sys.argv) >= 3:
args = sys.argv[3:]
else:
args = []
cron_class.job(args)
except KeyboardInterrupt:
log.error("aborting.")
log.info("Job complete")

View File

@@ -168,7 +168,10 @@ CELERYBEAT_SCHEDULE = {
"task": "eve_api.tasks.queue_apikey_updates",
"schedule": timedelta(minutes=10),
},
"alliance-update": {
"task": "import_alliance_details",
"schedule": timedelta(hours=6),
},
}
CELERY_SEND_TASK_ERROR_EMAILS = True