cron_tasks.py 1.35 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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

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
@cron(0, 0, -1, -1, -1, target="spooler")  # everyday at midnight
@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()


40 41 42 43 44 45
@timer(60 * 60, target="spooler")  # run it every hour
@harakiri(60)
def update_univ_major_minor():
    update_denormalized_univ_major_minor()


46 47 48 49 50
@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()