Dispatcharr/apps/proxy/ts_proxy/config_helper.py
SergeantPanda 6ccc2b9a6d Enhance stream retrieval process with error handling and retry logic
- Updated `get_stream` method to return error reasons for better debugging.
- Improved `generate_stream_url` to handle errors and log specific issues.
- Implemented retry mechanism in `stream_ts` view for obtaining streams with exponential backoff.
- Added new configuration options for connection timeout and retry intervals.
2025-04-10 08:38:53 -05:00

77 lines
2.4 KiB
Python

"""
Helper module to access configuration values with proper defaults.
"""
from apps.proxy.config import TSConfig as Config
class ConfigHelper:
"""
Helper class for accessing configuration values with sensible defaults.
This simplifies code and ensures consistent defaults across the application.
"""
@staticmethod
def get(name, default=None):
"""Get a configuration value with a default fallback"""
return getattr(Config, name, default)
# Commonly used configuration values
@staticmethod
def connection_timeout():
"""Get connection timeout in seconds"""
return ConfigHelper.get('CONNECTION_TIMEOUT', 10)
@staticmethod
def client_wait_timeout():
"""Get client wait timeout in seconds"""
return ConfigHelper.get('CLIENT_WAIT_TIMEOUT', 30)
@staticmethod
def stream_timeout():
"""Get stream timeout in seconds"""
return ConfigHelper.get('STREAM_TIMEOUT', 60)
@staticmethod
def channel_shutdown_delay():
"""Get channel shutdown delay in seconds"""
return ConfigHelper.get('CHANNEL_SHUTDOWN_DELAY', 5)
@staticmethod
def initial_behind_chunks():
"""Get number of chunks to start behind"""
return ConfigHelper.get('INITIAL_BEHIND_CHUNKS', 10)
@staticmethod
def keepalive_interval():
"""Get keepalive interval in seconds"""
return ConfigHelper.get('KEEPALIVE_INTERVAL', 0.5)
@staticmethod
def cleanup_check_interval():
"""Get cleanup check interval in seconds"""
return ConfigHelper.get('CLEANUP_CHECK_INTERVAL', 3)
@staticmethod
def redis_chunk_ttl():
"""Get Redis chunk TTL in seconds"""
return ConfigHelper.get('REDIS_CHUNK_TTL', 60)
@staticmethod
def chunk_size():
"""Get chunk size in bytes"""
return ConfigHelper.get('CHUNK_SIZE', 8192)
@staticmethod
def max_retries():
"""Get maximum retry attempts"""
return ConfigHelper.get('MAX_RETRIES', 3)
@staticmethod
def max_stream_switches():
"""Get maximum number of stream switch attempts"""
return ConfigHelper.get('MAX_STREAM_SWITCHES', 10)
@staticmethod
def retry_wait_interval():
"""Get wait interval between connection retries in seconds"""
return ConfigHelper.get('RETRY_WAIT_INTERVAL', 0.5) # Default to 0.5 second