cron_tasks.py 1.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "base_app.settings.main")
import django  # noqa: E402

django.setup()

# END OF SETUP
# DON'T PUT DJANGO RELATED IMPORTS BEFORE THIS

import logging  # noqa: E402

13
14
15
16
from uwsgidecorators import harakiri, cron, timer  # noqa: E402
from backend_app.models.exchange import (
    update_denormalized_univ_major_minor,
)  # noqa: E402
17

18
from backend_app.models.university import update_denormalized_univ_field  # noqa: E402
19
20
21
22
23
24
25
26
27
28
from external_data.management.commands.utils import FixerData, UtcData  # noqa: E402
from base_app.management.commands.clean_user_accounts import (
    ClearUserAccounts,
    ClearSessions,
)  # noqa: E402

logger = logging.getLogger("django")


# @timer(60, target="spooler")  # use this for tests
29
@timer(3 * 60 * 60, target="spooler")  # run it three hours
30
31
32
33
34
35
36
37
38
39
40
@harakiri(40)
def update_currencies(num):
    FixerData().update()


@cron(5, 0, -1, -1, -1, target="spooler")  # everyday at 5 past midnight
@harakiri(60 * 10)  # shouldn't take more than 10 minutes to run
def update_utc_ent(num):
    UtcData().update()


41
42
@timer(60 * 60, target="spooler")  # run it every hour
@harakiri(60)
Florent Chehab's avatar
Florent Chehab committed
43
def update_extra_denormalization(num):
44
    update_denormalized_univ_major_minor()
Florent Chehab's avatar
Florent Chehab committed
45
    update_denormalized_univ_field()
46
47


48
49
50
51
52
@cron(20, 0, -1, -1, -1, target="spooler")  # everyday at 20 past midnight
@harakiri(60 * 5)  # shouldn't take more than 5 minutes to run
def clear_and_clean_sessions(num):
    ClearUserAccounts.run()
    ClearSessions.run()