
    `?i                        d dl mZmZmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
mZmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d
dlmZ dZd ZdZdZdZh dZ G d de      Z  eddd       G d d             Z!	 d eeedddZ" eddd       G d d             Z# eddd       G d d             Z$ eddd       G d d             Z%y)!    )	dataclassfieldreplace)datetime)isclassiscoroutinefunction)AnyCallableDictOptional)async_to_syncsync_to_async)TextChoices)normalize_json)import_string)pgettext_lazy   )TaskResultMismatchdefaultd   i>   errorsstatus
started_at
worker_idsenqueued_atfinished_at_return_valuelast_attempted_atc                   d    e Zd Zd edd      fZd edd      fZd edd      fZd edd	      fZy
)TaskResultStatusREADYTaskReadyRUNNINGRunningFAILEDFailed
SUCCESSFUL
SuccessfulN)__name__
__module____qualname__r   r!   r$   r&   r(        c/home/cursorai/projects/django-cronjob-utils/venv/lib/python3.12/site-packages/django/tasks/base.pyr    r        sF    mFG45E-	:;Gfh78Ffl CDJr.   r    T)frozenslotskw_onlyc                       e Zd ZU eed<   eed<   eed<   eed<   ee   ed<   dZ	e
ed<   d Zed	        Zd
d
d
d
ddZd Zd Zd Zd Zd Zd Zd Zed        Zy
)r"   priorityfuncbackend
queue_name	run_afterFtakes_contextc                 B    | j                         j                  |        y N)get_backendvalidate_taskselfs    r/   __post_init__zTask.__post_init__6   s    ((.r.   c                 .    | j                   j                  S r;   )r5   r*   r>   s    r/   namez	Task.name9   s    yy!!!r.   N)r4   r7   r8   r6   c                V    i }|||d<   |||d<   |||d<   |||d<   t        | fi |S )z)Create a new Task with modified defaults.r4   r7   r8   r6   )r   )r?   r4   r7   r8   r6   changess         r/   usingz
Task.using=   sY     "*GJ!$.GL! #,GK !(GIt'w''r.   c                 D    | j                         j                  | ||      S )!Queue up the Task to be executed.)r<   enqueuer?   argskwargss      r/   rH   zTask.enqueueR   s     !))$f==r.   c                 `   K   | j                         j                  | ||       d{   S 7 w)rG   N)r<   aenqueuerI   s      r/   rM   zTask.aenqueueV   s*     %%'00tVDDDDs   %.,.c                     | j                         j                  |      }|j                  j                  | j                  k7  r#t	        d|j                  j
                  d      |S )z
        Retrieve a task result by id.

        Raise TaskResultDoesNotExist if such result does not exist, or raise
        TaskResultMismatch if the result exists but belongs to another Task.
        Task does not match (received ))r<   
get_resulttaskr5   r   module_pathr?   	result_idresults      r/   rQ   zTask.get_resultZ   s^     !!#..y9;;tyy($01H1H0K1M  r.   c                    K   | j                         j                  |       d{   }|j                  j                  | j                  k7  r#t	        d|j                  j
                  d      |S 7 Lw)zSee get_result().NrO   rP   )r<   aget_resultrR   r5   r   rS   rT   s      r/   rX   zTask.aget_resulth   si     '')55i@@;;tyy($01H1H0K1M   As   #A4A2AA4c                     t        | j                        r t        | j                        |i |S  | j                  |i |S r;   )r   r5   r   rI   s      r/   callz	Task.callq   s?    tyy)+=+T<V<<tyy$)&))r.   c                    K   t        | j                        r | j                  |i | d {   S  t        | j                        |i | d {   S 7 '7 wr;   )r   r5   r   rI   s      r/   acallz
Task.acallv   sR     tyy)"D3F333-]499-t>v>>> 4>s!   +AA"AAAAc                 ,    ddl m} || j                     S )Nr   task_backends) r_   r6   )r?   r_   s     r/   r<   zTask.get_backend{   s    #T\\**r.   c                 `    | j                   j                   d| j                   j                   S )N.)r5   r+   r,   r>   s    r/   rS   zTask.module_path   s)    ))&&'q)?)?(@AAr.   )r*   r+   r,   int__annotations__r
   strr   r   r9   boolr@   propertyrB   rE   rH   rM   rQ   rX   rZ   r\   r<   rS   r-   r.   r/   r"   r"   +   s    M
NLO!!  M4/ " " (*>E*
?
+
 B Br.   r"   NF)r4   r7   r6   r9   c                B    ddl m fd}| r ||       S |S )Nr   r^   c                 8       j                  | d       S )N)r4   r5   r7   r6   r9   r8   )
task_class)fr6   r4   r7   r9   r_   s    r/   wrapperztask.<locals>.wrapper   s2    W%00!' 1 
 	
r.   )r`   r_   )functionr4   r7   r6   r9   rl   r_   s    ```` @r/   rR   rR      s'      
 
 x  Nr.   c                   2    e Zd ZU eed<   eed<   ed        Zy)	TaskErrorexception_class_path	tracebackc                     t        | j                        }t        |      rt        |t              st        | j                  d      |S )Nz& does not reference a valid exception.)r   rp   r   
issubclassBaseException
ValueError)r?   exception_classs     r/   rv   zTaskError.exception_class   sQ     ((A(AB'z]0
 ,,//UV  r.   N)r*   r+   r,   re   rd   rg   rv   r-   r.   r/   ro   ro      s    N
 
r.   ro   c                      e Zd ZU eed<   eed<   eed<   ee   ed<   ee   ed<   ee   ed<   ee   ed<   e	ed<   e
eef   ed	<   eed
<   e	e   ed<   e	e   ed<    edd      Zee   ed<   d Zed        Zed        Zed        Zd Zd Zy)
TaskResultrR   idr   r   r   r   r   rJ   rK   r6   r   r   FN)initr   r   c                     t         j                  | dt        | j                               t         j                  | dt        | j                               y )NrJ   rK   )object__setattr__r   rJ   rK   r>   s    r/   r@   zTaskResult.__post_init__   s8    4		)BC4>$+++FGr.   c                     | j                   t        j                  k(  r| j                  S | j                   t        j                  k(  rt        d      t        d      )z
        The return value of the task.

        If the task didn't succeed, an exception is raised.
        This is to distinguish against the task returning None.
        zTask failedzTask has not finished yet)r   r    r(   r   r&   ru   r>   s    r/   return_valuezTaskResult.return_value   sM     ;;*555%%%[[,333]++899r.   c                 Z    | j                   t        j                  t        j                  hv S r;   )r   r    r&   r(   r>   s    r/   is_finishedzTaskResult.is_finished   s$    {{/668H8S8STTTr.   c                 ,    t        | j                        S r;   )lenr   r>   s    r/   attemptszTaskResult.attempts   s    4??##r.   c           	          | j                   j                         j                  | j                        }t        D ]#  }t
        j                  | |t        ||             % y)z0Reload the cached task data from the task store.N)rR   r<   rQ   ry   TASK_REFRESH_ATTRSr|   r}   getattrr?   refreshed_taskattrs      r/   refreshzTaskResult.refresh   sF    ..0;;DGGD&DtT7>4+HI 'r.   c           	         K   | j                   j                         j                  | j                         d{   }t        D ]#  }t
        j                  | |t        ||             % y7 1w)zA
        Reload the cached task data from the task store
        N)rR   r<   rX   ry   r   r|   r}   r   r   s      r/   arefreshzTaskResult.arefresh   sU       $yy446BB477KK&DtT7>4+HI ' Ls   7A-A+2A-)r*   r+   r,   r"   rd   re   r    r   r   listr   r	   ro   r   r   r@   rg   r   r   r   r   r   r-   r.   r/   rx   rx      s    
JG(##""(##  ))
JcNLOS	#(eT#BM8C=BH : : U U $ $JJr.   rx   c                   (    e Zd ZU eed<   ed        Zy)TaskContexttask_resultc                 .    | j                   j                  S r;   )r   r   r>   s    r/   attemptzTaskContext.attempt   s    (((r.   N)r*   r+   r,   rx   rd   rg   r   r-   r.   r/   r   r      s    ) )r.   r   r;   )&dataclassesr   r   r   r   inspectr   r   typingr	   r
   r   r   asgiref.syncr   r   django.db.models.enumsr   django.utils.jsonr   django.utils.module_loadingr   django.utils.translationr   
exceptionsr   DEFAULT_TASK_BACKEND_ALIASDEFAULT_TASK_PRIORITYDEFAULT_TASK_QUEUE_NAMETASK_MAX_PRIORITYTASK_MIN_PRIORITYr   r    r"   rR   ro   rx   r   r-   r.   r/   <module>r      s   1 1  0 0 0 5 . , 5 2 *&  #   	 E{ E $dD1VB VB 2VBt  #&&2 $dD1  2$ $dD1<J <J 2<J~ $dD1) ) 2)r.   