Merge branch 'master' into 'v2.9.x'

Merge Chunking Updates from Master

See merge request allianceauth/allianceauth!1351
This commit is contained in:
Ariel Rin 2021-10-20 05:00:57 +00:00
commit 2da78f7793

View File

@ -43,23 +43,36 @@ def run_model_update():
# update existing corp models
for corp in EveCorporationInfo.objects.all().values('corporation_id'):
update_corp.apply_async(
args=[corp['corporation_id']], priority=TASK_PRIORITY
)
update_corp.apply_async(args=[corp['corporation_id']], priority=TASK_PRIORITY)
# update existing alliance models
for alliance in EveAllianceInfo.objects.all().values('alliance_id'):
update_alliance.apply_async(
args=[alliance['alliance_id']], priority=TASK_PRIORITY
)
update_alliance.apply_async(args=[alliance['alliance_id']], priority=TASK_PRIORITY)
#update existing character models if required
# update existing character models
character_ids = EveCharacter.objects.all().values_list('character_id', flat=True)
for character_ids_chunk in chunks(character_ids, CHUNK_SIZE):
update_character_chunk.apply_async(
args=[character_ids_chunk], priority=TASK_PRIORITY
)
@shared_task
def update_character_chunk(character_ids_chunk: list):
"""Update a list of character from ESI"""
try:
affiliations_raw = providers.provider.client.Character\
.post_characters_affiliation(characters=character_ids_chunk).result()
character_names = providers.provider.client.Universe\
.post_universe_names(ids=character_ids_chunk).result()
except:
logger.error("Failed to bulk update characters. Attempting single updates")
for character_id in character_ids_chunk:
update_character.apply_async(
args=[character_id], priority=TASK_PRIORITY
)
return
affiliations = {
affiliation.get('character_id'): affiliation