27 lines
913 B
Python
27 lines
913 B
Python
from django.db import close_old_connections
|
|
from celery import shared_task
|
|
from channels.layers import get_channel_layer
|
|
from asgiref.sync import async_to_sync
|
|
|
|
from .models import Torrent, File
|
|
from .utils import transmission_handler
|
|
from app.utils import send_sync_channel_message
|
|
|
|
|
|
@shared_task
|
|
def update_transmission_data():
|
|
data = transmission_handler.get_all_data()
|
|
|
|
updated_torrents = []
|
|
for torrent in Torrent.objects.all():
|
|
if torrent.id in data and torrent.transmission_data != data[torrent.id]:
|
|
torrent.transmission_data = data[torrent.id]
|
|
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
|
|
})
|
|
|