
    {iW              	           d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ  e	e      Z ej                  dd	      d
ededeeef   fd       Z ej                  d      deeef   fd       Zdedeeef   fdZd
ededefdZg dZy)z+
Celery Tasks - Background Task Processing
    N)AnyDict)current_task)get_task_logger)
celery_appTsend_welcome_email)bindname
user_email	user_namereturnc                    	 t         j                  d| d|        t        j                  d       | j                  j
                  ||dt        j                         d}t         j                  d|        |S # t        $ r:}t         j                  dt        |              | j                  |dd	
      d}~ww xY w)z
    Send welcome email task - Simple example for demonstration
    
    Args:
        user_email: User's email address
        user_name: User's display name
        
    Returns:
        Dict containing task result information
    zSending welcome email to z
 for user    sent)task_idemailr
   status	timestampz#Welcome email sent successfully to zWelcome email sending failed: <      )exc	countdownmax_retriesN)
loggerinfotimesleeprequestid	Exceptionerrorstrretry)selfr   r   resultr   s        N/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/src/worker/tasks.pyr   r      s    ?/
|:i[QR 	

1 ||
 	9*FG ?5c#hZ@AjjSBAj>>?s   A7A: :	B=5B88B=health_check)r
   c                      t         j                  d       dt        j                         t        rt        j                  j
                  dS ddS )zv
    Health check task for monitoring worker status
    
    Returns:
        Dict containing health check result
    zPerforming health checkhealthyunknown)r   r   	worker_id)r   r   r   r   r   hostname     r&   r'   r'   7   sK     KK)* YY[6B\))22  IR r.   r   c                 .   t         sddiS 	 t        j                  |       }| |j                  |j                  |j                  |j
                  dS # t        $ r:}t        j                  dt        |              | dt        |      dcY d}~S d}~ww xY w)z
    Get status of a task by ID
    
    Args:
        task_id: Celery task ID
        
    Returns:
        Dict containing task status information
    r!   Celery not available)r   r   r%   	traceback	date_donezError getting task status: UNKNOWN)r   r   r!   N)
r   AsyncResultr   r%   r1   r2   r    r   r!   r"   )r   r%   r   s      r&   get_task_statusr5   I   s     /00
''0 mmmm))))
 	
  
23s8*=>X
 	

s   AA 	B/B	BBc                 h    t         st        d      t        j                  | |      }|j                  S )zX
    Trigger welcome email task from FastAPI
    
    Returns:
        str: Task ID
    r0   )r   RuntimeErrorr   delayr   )r   r   tasks      r&   trigger_welcome_emailr:   j   s.     122##J	:D77Nr.   )r   r'   r5   r:   )__doc__loggingr   typingr   r   celeryr   celery.utils.logr   src.worker.celery_appr   __name__r   r9   r"   r   r'   r5   r:   __all__r-   r.   r&   <module>rC      s        , , 
	" d!56$? $? $?c3h $? 7$?N n%d38n  &"
S 
T#s(^ 
Bc c c r.   