diff --git a/app/app/settings.py b/app/app/settings.py index 3d9c985..7060834 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -254,3 +254,4 @@ TRANSMISSION = { "username": getenv("TRANSMISSION_USERNAME"), "password": getenv("TRANSMISSION_PASSWORD") } +TORRENT_TTL = int(getenv("TORRENT_TTL", 90*24*60*60)) # 90 jours \ No newline at end of file diff --git a/app/dev_run.sh b/app/dev_run.sh index 9ce681c..bc519c4 100644 --- a/app/dev_run.sh +++ b/app/dev_run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash CORES=$(nproc) WORKERS=$((2 * CORES + 1)) diff --git a/app/torrent/management/commands/torrent_event.py b/app/torrent/management/commands/torrent_event.py index 4dfaa09..9c757f8 100644 --- a/app/torrent/management/commands/torrent_event.py +++ b/app/torrent/management/commands/torrent_event.py @@ -1,3 +1,5 @@ +from django.conf import settings +from django.utils import timezone from django.core.management.base import BaseCommand from django.db import close_old_connections @@ -5,6 +7,7 @@ import time import signal import sys import traceback +from datetime import timedelta from torrent.models import Torrent from torrent.utils import transmission_handler @@ -27,11 +30,20 @@ def update_transmission_data(): }) +def clean_old_torrents(): + expired_date = timezone.now() - timedelta(days=settings.TORRENT_TTL) + Torrent.objects.filter(date_created__lt=expired_date).first().delete() + + class Command(BaseCommand): task_schedule = { "update_transmission_data": { "func": update_transmission_data, "schedule": 5.0 + }, + "clean_old_torrents": { + "func": clean_old_torrents, + "schedule": 60.0 } } histories = {}