-
Notifications
You must be signed in to change notification settings - Fork 0
/
webworker.py
60 lines (47 loc) · 1.52 KB
/
webworker.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
from apscheduler.schedulers.background import BackgroundScheduler
from work import *
from src.models import Players
from src.models import Matches
from src.models import Practices
from src.models import AttendanceHistory
from django.contrib.admin.models import LogEntry
from axes.utils import reset
import os
import datetime
def run_web_script():
os.system('gunicorn config.wsgi --log-file -') # Runs forever
def start_scheduler():
scheduler = BackgroundScheduler()
scheduler.add_job(doWork, 'interval', seconds=1)
scheduler.start() # Runs in the 'background'
def clearEverything():
# Delete all django-axes lockouts and access records
reset()
# Erase all entries in these tables
tables = [
Players.objects.all(),
Matches.objects.all(),
Practices.objects.all(),
AttendanceHistory.objects.all(),
LogEntry.objects.all(),
]
for table in tables:
for entry in table:
entry.delete()
def doWork():
'''
We need to clear the database entries once in a while so we don't go over the row limit in the Heroku Postgres database.
Therefore, we will reset all entries during July, since school is not in session.
Otherwise, update the attendances and matches as usual.
'''
if datetime.datetime.now().month == 7:
clearEverything()
else:
checkForMatchUpdates()
checkForPracticeUpdates()
deleteLogEntries()
def run():
start_scheduler()
run_web_script()
if __name__ == '__main__':
run()