"""
RQ Worker Configuration

This module provides configuration settings for RQ workers.
Workers can be started with these settings using the start_workers.sh script.

Usage:
    # In worker startup
    from config.rq_config import WORKER_CONFIG

    worker = Worker(
        queues=WORKER_CONFIG['queues'],
        connection=redis_conn,
        **WORKER_CONFIG['worker_kwargs']
    )
"""

import os

from app.tasks import ALL_QUEUES, QUEUE_AI_TASKS, QUEUE_COMBAT_TASKS, QUEUE_MARKETPLACE_TASKS


# Redis URL for workers
REDIS_URL = os.getenv('REDIS_URL', 'redis://localhost:6379/0')


# Worker configuration
WORKER_CONFIG = {
    # Queues to listen on (in priority order)
    'queues': ALL_QUEUES,

    # Worker behavior settings
    'worker_kwargs': {
        'name': None,  # Auto-generated if None
        'default_result_ttl': 3600,  # 1 hour
        'default_worker_ttl': 420,  # 7 minutes
        'job_monitoring_interval': 5,  # Check job status every 5 seconds
        'disable_default_exception_handler': False,
        'log_job_description': True,
    },

    # Burst mode (process jobs then exit)
    'burst': False,

    # Logging
    'logging_level': os.getenv('LOG_LEVEL', 'INFO'),
}


# Scheduler configuration (for periodic tasks)
SCHEDULER_CONFIG = {
    'interval': 60,  # Check for scheduled jobs every 60 seconds
}


# Job retry configuration
RETRY_CONFIG = {
    'max_retries': 3,
    'retry_delays': [60, 300, 900],  # 1 min, 5 min, 15 min
}


# Queue-specific worker settings (for specialized workers)
SPECIALIZED_WORKERS = {
    'ai_worker': {
        'queues': [QUEUE_AI_TASKS],
        'description': 'Dedicated worker for AI generation tasks',
    },
    'combat_worker': {
        'queues': [QUEUE_COMBAT_TASKS],
        'description': 'Dedicated worker for combat processing',
    },
    'marketplace_worker': {
        'queues': [QUEUE_MARKETPLACE_TASKS],
        'description': 'Dedicated worker for marketplace tasks',
    },
}
