vpn integration
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import close_old_connections
|
||||
|
||||
import time
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from datetime import timedelta
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import close_old_connections
|
||||
from django.utils import timezone
|
||||
|
||||
from app.utils import send_sync_channel_message
|
||||
from torrent.models import Torrent
|
||||
from torrent.utils import transmission_handler
|
||||
from app.utils import send_sync_channel_message
|
||||
|
||||
|
||||
def update_transmission_data():
|
||||
@@ -24,10 +23,11 @@ def update_transmission_data():
|
||||
updated_torrents.append(torrent)
|
||||
if updated_torrents:
|
||||
Torrent.objects.bulk_update(updated_torrents, ["transmission_data"])
|
||||
send_sync_channel_message("torrent", "transmission_data_updated", {
|
||||
torrent.id: torrent.transmission_data
|
||||
for torrent in updated_torrents
|
||||
})
|
||||
send_sync_channel_message(
|
||||
"torrent",
|
||||
"transmission_data_updated",
|
||||
{torrent.id: torrent.transmission_data for torrent in updated_torrents},
|
||||
)
|
||||
|
||||
|
||||
def clean_old_torrents():
|
||||
@@ -37,24 +37,16 @@ def clean_old_torrents():
|
||||
print(f"delete torrent {torrent.name}")
|
||||
torrent.delete()
|
||||
|
||||
|
||||
def update_peer_port():
|
||||
transmission_handler.update_vpn_port()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
task_schedule = {
|
||||
"update_transmission_data": {
|
||||
"func": update_transmission_data,
|
||||
"schedule": 5.0
|
||||
},
|
||||
"clean_old_torrents": {
|
||||
"func": clean_old_torrents,
|
||||
"schedule": 5.0
|
||||
},
|
||||
"update_peer_port": {
|
||||
"func": update_peer_port,
|
||||
"schedule": 10.0
|
||||
}
|
||||
"update_transmission_data": {"func": update_transmission_data, "schedule": 5.0},
|
||||
"clean_old_torrents": {"func": clean_old_torrents, "schedule": 5.0},
|
||||
"update_peer_port": {"func": update_peer_port, "schedule": 10.0},
|
||||
}
|
||||
histories = {}
|
||||
run = True
|
||||
@@ -66,7 +58,10 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.SUCCESS("start"))
|
||||
while self.run:
|
||||
for name, task in self.task_schedule.items():
|
||||
if name not in self.histories or time.time() - self.histories[name] > task["schedule"]:
|
||||
if (
|
||||
name not in self.histories
|
||||
or time.time() - self.histories[name] > task["schedule"]
|
||||
):
|
||||
self.call_func(name)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user