This repository was archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtasks.py
90 lines (68 loc) · 2.96 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import unicode_literals
from django.utils import timezone
from .managers.standings import StandingsManager
from .models import ContactSet, StandingsRevocation
import logging
import datetime
from alliance_auth.celeryapp import app
logger = logging.getLogger(__name__)
@app.task(name="standings_requests.standings_update")
def standings_update():
logger.info("Standings API update running")
# Run standings update first
st = StandingsManager.api_update_alliance_standings()
if st is None:
logger.warn("Standings API update returned None (API error probably), aborting standings update")
return
StandingsManager.process_pending_standings()
@app.task(name="standings_requests.validate_standings_requests")
def validate_standings_requests():
logger.info("Validating standings request running")
count = StandingsManager.validate_standings_requests()
logger.info("Deleted {0} standings requests".format(count))
@app.task(name="standings_requests.update_associations_auth")
def update_associations_auth():
"""
Update associations from local auth data (Main character, corporations)
"""
logger.info("Associations updating from Auth")
StandingsManager.update_character_associations_auth()
logger.info("Finished Associations update from Auth")
@app.task(name="standings_requests.update_associations_api")
def update_associations_api():
"""
Update character associations from the EVE API (corporations)
"""
logger.info("Associations updating from EVE API")
StandingsManager.update_character_associations_api()
logger.info("Finished associations update from EVE API")
@app.task(name="standings_requests.purge_stale_data")
def purge_stale_data():
"""
Delete all the data which is beyond its useful life. There is no harm in disabling this
if you wish to keep everything.
"""
purge_stale_standings_data()
purge_stale_revocations()
def purge_stale_standings_data():
# Standings Data
# Keep only the last 48 hours and at least one record (even if its stale)
logger.info("Purging stale standings data")
cutoff_date = timezone.now() - datetime.timedelta(hours=48)
latest_standings = ContactSet.objects.latest()
if latest_standings is not None:
standings = ContactSet.objects.filter(date__lt=cutoff_date).exclude(id=latest_standings.id)
if len(standings):
logger.debug("Deleting Standings {0}".format(standings))
standings.delete()
else:
logger.debug("No Standings to delete")
else:
logger.warn("No standings available, nothing to delete")
def purge_stale_revocations():
logger.info("Purging stale revocations data")
cutoff_date = timezone.now() - datetime.timedelta(days=7)
revocs = StandingsRevocation.objects.exclude(effective=False).filter(effectiveDate__lt=cutoff_date)
count = len(revocs)
revocs.delete()
logger.debug("Deleted {0} standings revocations".format(count))