Change celery tasks to shared task decorator

This commit is contained in:
Basraah 2017-12-11 00:26:07 +10:00
parent 676e68a2bb
commit f037d7fea6
14 changed files with 46 additions and 43 deletions

View File

@ -2,14 +2,14 @@ import logging
from esi.errors import TokenExpiredError, TokenInvalidError
from esi.models import Token
from celery import shared_task
from allianceauth.authentication.models import CharacterOwnership
from allianceauth.celery import app
logger = logging.getLogger(__name__)
@app.task
@shared_task
def check_character_ownership(owner_hash):
tokens = Token.objects.filter(character_owner_hash=owner_hash)
if tokens:
@ -31,7 +31,7 @@ def check_character_ownership(owner_hash):
CharacterOwnership.objects.filter(owner_hash=owner_hash).delete()
@app.task
@shared_task
def check_all_character_ownership():
for c in CharacterOwnership.objects.all().only('owner_hash'):
check_character_ownership.delay(c.owner_hash)

View File

@ -1,14 +1,14 @@
from allianceauth.celery import app
from celery import shared_task
from allianceauth.corputils import CorpStats
@app.task
@shared_task
def update_corpstats(pk):
cs = CorpStats.objects.get(pk=pk)
cs.update()
@app.task
@shared_task
def update_all_corpstats():
for cs in CorpStats.objects.all():
update_corpstats.delay(cs.pk)

View File

@ -1,6 +1,6 @@
import logging
from allianceauth.celery import app
from celery import shared_task
from .models import EveAllianceInfo
from .models import EveCharacter
from .models import EveCorporationInfo
@ -8,22 +8,22 @@ from .models import EveCorporationInfo
logger = logging.getLogger(__name__)
@app.task
@shared_task
def update_corp(corp_id):
EveCorporationInfo.objects.update_corporation(corp_id)
@app.task
@shared_task
def update_alliance(alliance_id):
EveAllianceInfo.objects.update_alliance(alliance_id).populate_alliance()
@app.task
@shared_task
def update_character(character_id):
EveCharacter.objects.update_character(character_id)
@app.task
@shared_task
def run_model_update():
# update existing corp models
for corp in EveCorporationInfo.objects.all().values('corporation_id'):

View File

@ -4,8 +4,8 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from allianceauth.notifications import notify
from celery import shared_task
from allianceauth.celery import app
from allianceauth.services.hooks import NameFormatter
from .manager import DiscordOAuthManager, DiscordApiBackoff
from .models import DiscordUser
@ -57,7 +57,7 @@ class DiscordTasks:
return True
@staticmethod
@app.task(bind=True, name='discord.update_groups')
@shared_task(bind=True, name='discord.update_groups')
def update_groups(task_self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating discord groups for user %s" % user)
@ -87,14 +87,14 @@ class DiscordTasks:
logger.debug("User does not have a discord account, skipping")
@staticmethod
@app.task(name='discord.update_all_groups')
@shared_task(name='discord.update_all_groups')
def update_all_groups():
logger.debug("Updating ALL discord groups")
for discord_user in DiscordUser.objects.exclude(uid__exact=''):
DiscordTasks.update_groups.delay(discord_user.user.pk)
@staticmethod
@app.task(bind=True, name='discord.update_nickname')
@shared_task(bind=True, name='discord.update_nickname')
def update_nickname(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating discord nickname for user %s" % user)
@ -118,7 +118,7 @@ class DiscordTasks:
logger.debug("User %s does not have a discord account" % user)
@staticmethod
@app.task(name='discord.update_all_nicknames')
@shared_task(name='discord.update_all_nicknames')
def update_all_nicknames():
logger.debug("Updating ALL discord nicknames")
for discord_user in DiscordUser.objects.exclude(uid__exact=''):

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import DiscourseManager
@ -40,7 +40,7 @@ class DiscourseTasks:
return False
@staticmethod
@app.task(bind=True, name='discourse.update_groups')
@shared_task(bind=True, name='discourse.update_groups')
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating discourse groups for user %s" % user)
@ -52,7 +52,7 @@ class DiscourseTasks:
logger.debug("Updated user %s discourse groups." % user)
@staticmethod
@app.task(name='discourse.update_all_groups')
@shared_task(name='discourse.update_all_groups')
def update_all_groups():
logger.debug("Updating ALL discourse groups")
for discourse_user in DiscourseUser.objects.filter(enabled=True):

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from .models import MumbleUser
logger = logging.getLogger(__name__)
@ -26,7 +26,7 @@ class MumbleTasks:
MumbleUser.objects.all().delete()
@staticmethod
@app.task(bind=True, name="mumble.update_groups")
@shared_task(bind=True, name="mumble.update_groups")
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating mumble groups for user %s" % user)
@ -46,7 +46,7 @@ class MumbleTasks:
return False
@staticmethod
@app.task(name="mumble.update_all_groups")
@shared_task(name="mumble.update_all_groups")
def update_all_groups():
logger.debug("Updating ALL mumble groups")
for mumble_user in MumbleUser.objects.exclude(username__exact=''):

View File

@ -3,8 +3,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from allianceauth.notifications import notify
from celery import shared_task
from allianceauth.celery import app
from allianceauth.services.modules.openfire.manager import OpenfireManager
from allianceauth.services.hooks import NameFormatter
from .models import OpenfireUser
@ -40,7 +40,7 @@ class OpenfireTasks:
OpenfireUser.objects.all().delete()
@staticmethod
@app.task(bind=True, name="openfire.update_groups")
@shared_task(bind=True, name="openfire.update_groups")
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating jabber groups for user %s" % user)
@ -61,7 +61,7 @@ class OpenfireTasks:
logger.debug("User does not have an openfire account")
@staticmethod
@app.task(name="openfire.update_all_groups")
@shared_task(name="openfire.update_all_groups")
def update_all_groups():
logger.debug("Updating ALL jabber groups")
for openfire_user in OpenfireUser.objects.exclude(username__exact=''):

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import Phpbb3Manager
@ -35,7 +35,7 @@ class Phpbb3Tasks:
return False
@staticmethod
@app.task(bind=True, name="phpbb3.update_groups")
@shared_task(bind=True, name="phpbb3.update_groups")
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating phpbb3 groups for user %s" % user)
@ -56,7 +56,7 @@ class Phpbb3Tasks:
logger.debug("User does not have a Phpbb3 account")
@staticmethod
@app.task(name="phpbb3.update_all_groups")
@shared_task(name="phpbb3.update_all_groups")
def update_all_groups():
logger.debug("Updating ALL phpbb3 groups")
for user in Phpbb3User.objects.exclude(username__exact=''):

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import SeatManager
@ -34,7 +34,7 @@ class SeatTasks:
return False
@staticmethod
@app.task(bind=True)
@shared_task(bind=True)
def update_roles(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating SeAT roles for user %s" % user)
@ -56,7 +56,7 @@ class SeatTasks:
logger.debug("User %s does not have a SeAT account")
@staticmethod
@app.task
@shared_task
def update_all_roles():
logger.debug("Updating ALL SeAT roles")
for user in SeatUser.objects.all():

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import SmfManager
@ -39,7 +39,7 @@ class SmfTasks:
SmfUser.objects.all().delete()
@staticmethod
@app.task(bind=True, name="smf.update_groups")
@shared_task(bind=True, name="smf.update_groups")
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating smf groups for user %s" % user)
@ -60,7 +60,7 @@ class SmfTasks:
logger.debug("User does not have an smf account")
@staticmethod
@app.task(name="smf.update_all_groups")
@shared_task(name="smf.update_all_groups")
def update_all_groups():
logger.debug("Updating ALL smf groups")
for user in SmfUser.objects.exclude(username__exact=''):

View File

@ -2,8 +2,8 @@ import logging
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from celery import shared_task
from allianceauth.celery import app
from allianceauth.notifications import notify
from allianceauth.services.hooks import NameFormatter
from .manager import Teamspeak3Manager
@ -37,7 +37,7 @@ class Teamspeak3Tasks:
return False
@staticmethod
@app.task()
@shared_task
def run_ts3_group_update():
logger.debug("TS3 installed. Syncing local group objects.")
with Teamspeak3Manager() as ts3man:
@ -56,7 +56,7 @@ class Teamspeak3Tasks:
logger.info("Teamspeak3 disabled")
@staticmethod
@app.task(bind=True, name="teamspeak3.update_groups")
@shared_task(bind=True, name="teamspeak3.update_groups")
def update_groups(self, pk):
user = User.objects.get(pk=pk)
logger.debug("Updating user %s teamspeak3 groups" % user)
@ -81,7 +81,7 @@ class Teamspeak3Tasks:
logger.debug("User does not have a teamspeak3 account")
@staticmethod
@app.task(name="teamspeak3.update_all_groups")
@shared_task(name="teamspeak3.update_all_groups")
def update_all_groups():
logger.debug("Updating ALL teamspeak3 groups")
for user in Teamspeak3User.objects.exclude(uid__exact=''):

View File

@ -1,8 +1,8 @@
import logging
import redis
from celery import shared_task
from allianceauth.celery import app
from .hooks import ServicesHook
REDIS_CLIENT = redis.Redis()
@ -37,7 +37,7 @@ def only_one(function=None, key="", timeout=None):
return _dec(function) if function is not None else _dec
@app.task(bind=True)
@shared_task(bind=True)
def validate_services(self, user):
logger.debug('Ensuring user {} has permissions for active services'.format(user))
# Iterate through services hooks and have them check the validity of the user

View File

@ -0,0 +1,3 @@
from .celery import app as celery_app
__all__ = ['celery_app']

View File

@ -1,12 +1,12 @@
import os
import os, sys
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'allianceauth.project_template.project_name.settings.base')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django.conf import settings # noqa
app = Celery('alliance_auth')
app = Celery('devauth')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.