U
    	h                     @   sH  d Z ddlZddlmZ ddlmZ ejdd edZej	dd	d
 e
  ddiddiddiddidej_dej_dddddddddddddej_ejjdddddddgejdddddd dddd d!d"d#d d$d%d&d d'ej_dej_dej_eed(rejej_ejdd)d*d+ Zejdd)d,d- ZdS ).a  
Celery configuration for Stream Processor Django project.

This module configures Celery for handling background tasks such as:
- Stream capture and processing
- Jingle detection and ad break analysis
- Telegram notification sending
- Periodic maintenance tasks
- File system monitoring

Celery allows the application to process time-consuming tasks asynchronously,
improving user experience and system responsiveness.
    N)Celery)settingsDJANGO_SETTINGS_MODULEzcore.settingscorezdjango.conf:settingsZCELERY)	namespacequeuestream_processingjingle_detectionnotifications
monitoring)zapps.streams.tasks.*zapps.jingles.tasks.*zapps.notifications.tasks.*zapps.monitoring.tasks.*default)ZexchangeZrouting_key)r   r	   r
   r   i  iX  i  gzipjsonT   i  )Zresult_expiresZtask_time_limitZtask_soft_time_limitZresult_compressionZtask_serializerZresult_serializerZaccept_contenttimezoneZ
enable_utcZworker_prefetch_multiplierZworker_max_tasks_per_childZtask_acks_lateZtask_reject_on_worker_lostz10/m   <   )Z
rate_limitZmax_retriesZdefault_retry_delayz50/m      z100/m   
   )z!apps.streams.tasks.capture_streamz apps.jingles.tasks.detect_jinglez.apps.notifications.tasks.send_telegram_messageCELERY_BEAT_SCHEDULE)bindc                 C   s   t d| j d| jj S )ao  
    Debug task for testing Celery configuration.
    
    This task can be used to verify that Celery is properly configured
    and can execute tasks. It's primarily used for debugging and testing.
    
    Args:
        self: The task instance (automatically provided by bind=True)
        
    Returns:
        str: Debug information about the task execution
    z	Request: z$Debug task executed successfully at )printrequestid)self r   //var/www/html/JingleDetector/src/core/celery.py
debug_task   s    r   c                 C   sF   ddl m} td| d|  tjdrB|d| d|  dS )	a  
    Handle task failures for monitoring and alerting.
    
    This task is called when other tasks fail, allowing for centralized
    error handling, logging, and notification of failures.
    
    Args:
        self: The task instance
        task_id (str): ID of the failed task
        error (str): Error message from the failed task
        traceback (str): Stack trace of the failure
        
    Returns:
        bool: True if failure handling was successful
    r   )send_telegram_messagezTask z	 failed: ZENABLEDu&   🚨 Task Failure Alert 🚨
Task ID: z
Error: T)Zapps.notifications.tasksr    r   r   ZTELEGRAM_CONFIGgetdelay)r   Ztask_iderror	tracebackr    r   r   r   task_failure_handler   s    r%   )__doc__osceleryr   django.confr   environ
setdefaultappZconfig_from_objectZautodiscover_tasksconfZtask_routesZtask_default_queueZtask_queuesupdate	TIME_ZONEZtask_annotationsZworker_send_task_eventsZtask_send_sent_eventhasattrr   Zbeat_scheduletaskr   r%   r   r   r   r   <module>   s|   






