-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (38 loc) · 1.2 KB
/
main.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
import datetime as dt
import logging
import subprocess
import sys
import pytz
from project.celery_app import app
from project.schedule import Schedule
from project.sessions import get_retry_session
from project.settings import TIME_ZONE
from project.tasks import start_lesson, every_midnight
from project.tools import auth, get_cookies
logger = logging.getLogger(__name__)
tz = pytz.timezone(TIME_ZONE)
session = get_retry_session()
if not get_cookies(session).ok:
sys.exit(1)
if not auth(session).ok:
sys.exit(1)
def enqueue_lessons():
s = Schedule()
schedule = s.get_schedule(session)
print(schedule)
for day in schedule:
for time in schedule[day].keys():
date = dt.datetime.combine(day, time)
if dt.datetime.utcnow() < date + dt.timedelta(hours=1, minutes=30):
start_lesson.apply_async(eta=date)
def celery_purge():
app.control.purge()
def run_workers():
subprocess.run([
'celery', 'worker', '-A', 'project.celery_app',
'--pool', 'solo', '--loglevel', 'debug'
])
if __name__ == '__main__':
celery_purge()
every_midnight(enqueue_lessons)() # This doesn't work and I don't want to fix it.
run_workers()