from uwsgidecoratorsfallback import cron
from django.db import connection

from ocyan.main.utils import run_exclusive


@cron(20, 4, -1, -1, -1, target="spooler")  # every day at 4:20
def empty_trash(args):
    try:
        if not connection.is_usable():
            connection.close()

    except AttributeError:
        connection.close_if_unusable_or_obsolete()

    run_exclusive(
        "empty_trash", "--older_than_days=30"
    )  # checks for trash older than 30 days.
