#!/usr/bin/env python3
"""
Queue configuration using SqliteHuey for asynchronous file processing.
"""

import os
import logging
from huey import SqliteHuey
from datetime import timedelta

# Configure logging
logger = logging.getLogger('app')

# Ensure projects/queue_data directory exists
queue_data_dir = os.path.join(os.path.dirname(__file__), '..', 'projects', 'queue_data')
os.makedirs(queue_data_dir, exist_ok=True)

# Initialize SqliteHuey
huey = SqliteHuey(
    filename=os.path.join(queue_data_dir, 'huey.db'),
    name='file_processor',  # Queue name
    always_eager=False,  # Set to False to enable async processing
    utc=True,  # Use UTC time
)

# Set default task configuration
huey.store_errors = True  # Store error information
huey.max_retries = 3  # Maximum retry count
huey.retry_delay = timedelta(seconds=60)  # Retry delay

logger.info(f"SqliteHuey queue initialized, database path: {os.path.join(queue_data_dir, 'huey.db')}")