Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions dumpyarabot/aria2_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import socket
import subprocess
from collections import deque
from collections.abc import AsyncIterator
from dataclasses import dataclass
from pathlib import Path
from collections.abc import AsyncIterator

import aria2p
from rich.console import Console
from dumpyarabot.process_utils import _register_process_for_current_job, _unregister_process_for_current_job

from dumpyarabot.process_utils import (
_register_process_for_current_job,
_unregister_process_for_current_job,
)

console = Console()

Expand Down Expand Up @@ -103,10 +107,17 @@ def _find_free_port() -> int:
class Aria2Manager:
"""Manages an aria2c daemon and provides RPC-based download with progress tracking."""

def __init__(self, download_dir: str, split: int = 16, max_connection_per_server: int = 16):
def __init__(
self,
download_dir: str,
split: int = 16,
max_connection_per_server: int = 16,
log_download_names: bool = True,
):
self.download_dir = Path(download_dir)
self.split = split
self.max_connection_per_server = max_connection_per_server
self.log_download_names = log_download_names
self._process: asyncio.subprocess.Process | None = None
self._stderr_task: asyncio.Task[None] | None = None
self._stderr_lines: deque[str] = deque(maxlen=50)
Expand Down Expand Up @@ -255,7 +266,8 @@ async def download(
raise RuntimeError(f"Failed to add download for: {url}")

gid = download.gid
console.print(f"[blue]Download added (gid={gid}): {url}[/blue]")
if self.log_download_names:
console.print(f"[blue]Download added (gid={gid}): {url}[/blue]")

elapsed = 0.0
try:
Expand Down Expand Up @@ -283,7 +295,8 @@ async def download(
yield progress

if progress.is_complete:
console.print(f"[green]Download complete: {file_name}[/green]")
if self.log_download_names:
console.print(f"[green]Download complete: {file_name}[/green]")
return

if progress.is_error:
Expand Down
28 changes: 28 additions & 0 deletions dumpyarabot/arq_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import json
import logging
import os
import shutil
import signal as _signal
Expand All @@ -29,11 +30,38 @@
from rich.console import Console

from dumpyarabot.config import settings
from dumpyarabot.privacy import redact_urls
from dumpyarabot.schemas import JobCancelResult

console = Console()


class _RedactArqArguments(logging.Filter):
"""Prevent persisted firmware URLs from appearing in ARQ argument logs."""

def filter(self, record: logging.LogRecord) -> bool:
if isinstance(record.args, tuple):
record.args = tuple(
redact_urls(str(value), private=True)
if isinstance(value, (str, Exception))
else value
for value in record.args
)
elif isinstance(record.args, dict):
record.args = {
key: redact_urls(str(value), private=True)
if isinstance(value, (str, Exception))
else value
for key, value in record.args.items()
}
if isinstance(record.msg, str):
record.msg = redact_urls(record.msg, private=True)
return True


logging.getLogger("arq.worker").addFilter(_RedactArqArguments())


def get_redis_settings():
"""Parse Redis URL and return connection settings."""
parsed = urlparse(settings.REDIS_URL)
Expand Down
Loading