mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Initial work in bringing celery into Auth
This commit is contained in:
@@ -4,11 +4,11 @@ Admin interface models. Automatically detected by admin.autodiscover().
|
||||
from django.contrib import admin
|
||||
from eve_api.models import *
|
||||
|
||||
from eve_api.api_puller.accounts import import_eve_account
|
||||
from eve_api.tasks import import_apikey
|
||||
|
||||
def account_api_update(modeladmin, request, queryset):
|
||||
for obj in queryset:
|
||||
import_eve_account(obj.api_key, obj.api_user_id)
|
||||
import_apikey.delay(api_key=obj.api_key, api_userid=obj.api_user_id)
|
||||
|
||||
account_api_update.short_description = "Update account from the EVE API"
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ 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 UpdateAPIs():
|
||||
"""
|
||||
Updates all Eve API elements in the database
|
||||
@@ -33,28 +35,11 @@ class UpdateAPIs():
|
||||
accounts = EVEAccount.objects.filter(api_last_updated__lt=(datetime.datetime.now() - delta)).exclude(api_status=API_STATUS_ACC_EXPIRED).exclude(api_status=API_STATUS_AUTH_ERROR).order_by('api_last_updated')[:self.batches]
|
||||
self._logger.debug("%s account(s) to update" % len(accounts))
|
||||
for acc in accounts:
|
||||
self._logger.info("Updating UserID %s" % acc.api_user_id)
|
||||
self._logger.info("Queueing UserID %s for update" % acc.api_user_id)
|
||||
if not acc.user:
|
||||
acc.delete()
|
||||
continue
|
||||
eve_api.api_puller.accounts.import_eve_account(acc.api_key, acc.api_user_id)
|
||||
if acc.api_status == API_STATUS_OK:
|
||||
if acc.api_keytype == API_KEYTYPE_FULL and acc.characters.filter(director=1).count():
|
||||
donecorps = []
|
||||
for char in acc.characters.filter(director=1):
|
||||
if not char.corporation.id in donecorps:
|
||||
self._logger.info("Updating Corp %s" % char.corporation)
|
||||
pull_corp_members(acc.api_key, acc.api_user_id, char.id)
|
||||
char.corporation.query_and_update_corp()
|
||||
donecorps.append(char.corporation.id)
|
||||
|
||||
if self.settings['update_corp']:
|
||||
for char in acc.characters.all():
|
||||
try:
|
||||
char.corporation.query_and_update_corp()
|
||||
except:
|
||||
self._logger.error('Error updating %s' % corp)
|
||||
continue
|
||||
import_apikey.delay(api_key=acc.api_key, api_userid=acc.api_user_id)
|
||||
|
||||
class AllianceUpdate():
|
||||
"""
|
||||
|
||||
32
eve_api/tasks.py
Normal file
32
eve_api/tasks.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from celery.decorators import task
|
||||
from eve_api.api_puller.accounts import import_eve_account
|
||||
from eve_api.app_defines import *
|
||||
|
||||
@task()
|
||||
def import_apikey(api_userid, api_key, user=None, force_cache=False):
|
||||
acc = import_eve_account(api_key, api_userid, force_cache=force_cache)
|
||||
donecorps = []
|
||||
if acc and acc.api_status == API_STATUS_OK:
|
||||
if user and not acc.user:
|
||||
acc.user = user
|
||||
if acc.api_keytype == API_KEYTYPE_FULL and acc.characters.filter(director=1).count():
|
||||
donecorps = []
|
||||
for char in acc.characters.filter(director=1):
|
||||
if not char.corporation.id in donecorps:
|
||||
#pull_corp_members(acc.api_key, acc.api_user_id, char.id)
|
||||
char.corporation.query_and_update_corp()
|
||||
donecorps.append(char.corporation.id)
|
||||
|
||||
for char in acc.characters.all():
|
||||
try:
|
||||
if char.corporation.id not in donecorps:
|
||||
char.corporation.query_and_update_corp()
|
||||
donecorps.append(char.corporation.id)
|
||||
except:
|
||||
continue
|
||||
|
||||
acc.save()
|
||||
if acc.user:
|
||||
acc.user.get_profile().update_access()
|
||||
|
||||
return acc
|
||||
Reference in New Issue
Block a user