U
    di                     @   s   d Z ddl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dlmZ d	d
lmZ eejZeeeeZG dd dejZG dd dejZG dd dejZdS )zDatabase models.    N)states)GroupResultresult_from_tuple)settings)models)gettext_lazy   )managersc                   @   s  e Zd ZdZejeedddededdZ	ejddeded	d
Z
ejdeeddededd
ZejdededdZejdededdZejdejeededdZejdddededdZejdededdZejded ed!dZejddd"ed#ed$d%Zejded&ed'd(Zejded)ed*d+Zejdded,ed-d.Zejddd"ed/ed0d%Ze ZG d1d2 d2Zd3d4 Z d5d6 Z!dS )7
TaskResultzTask result/status.(DJANGO_CELERY_RESULTS_TASK_ID_MAX_LENGTH   TzTask IDz#Celery ID for the Task that was run
max_lengthuniqueverbose_name	help_textzPeriodic Task Namez'Name of the Periodic Task which was run)nullr   r   r   z	Task NamezName of the Task which was runzTask Positional ArgumentszBJSON representation of the positional arguments used with the task)r   r   r   zTask Named Argumentsz=JSON representation of the named arguments used with the task2   z
Task Statez#Current state of the task being run)r   defaultchoicesr   r   d   NZWorkerzWorker that executes the task)r   r   r   r   r      Result Content TypeContent type of the result datar   r   r   @   Result Encoding.The encoding used to save the task result dataFResult DataUThe data returned by the task.  Use content_encoding and content_type fields to read.r   r   editabler   r   Created DateTimez6Datetime field when the task result was created in UTCZauto_now_addr   r   Completed DateTimez1Datetime field when the task was completed in UTCZauto_nowr   r   	Tracebackz/Text of the traceback if the task generated one)Zblankr   r   r   zTask Meta InformationzHJSON meta information about the task, such as information on child tasksc                   @   sp   e Zd ZdZdgZedZedZej	dgddej	dgd	dej	d
gddej	dgddej	dgddgZ
dS )zTaskResult.MetaTable information.
-date_doneztask resultztask results	task_nameZdjango_cele_task_na_08aec9_idxfieldsnamestatusZdjango_cele_status_9b6201_idxworkerZdjango_cele_worker_d54dd8_idxdate_createdZdjango_cele_date_cr_f04a50_idx	date_doneZdjango_cele_date_do_f59aad_idxN__name__
__module____qualname____doc__Zordering_r   Zverbose_name_pluralr   ZIndexZindexes r8   r8   @/tmp/pip-unpacked-wheel-oj8imec1/django_celery_results/models.pyMeta^   s(   r:   c                 C   s.   | j | j| j| j| j| j| j| j| j| j	d
S )N
task_idr*   	task_argstask_kwargsr.   resultr1   	tracebackmetar/   r;   selfr8   r8   r9   as_dictt   s    zTaskResult.as_dictc                 C   s
   d | S )Nz <Task: {0.task_id} ({0.status})>)formatrB   r8   r8   r9   __str__   s    zTaskResult.__str__)"r3   r4   r5   r6   r   	CharFieldgetattrr   r7   r<   Zperiodic_task_namer*   	TextFieldr=   r>   r   ZPENDINGTASK_STATE_CHOICESr.   r/   content_typecontent_encodingr?   DateTimeFieldr0   r1   r@   rA   r
   ZTaskResultManagerobjectsr:   rD   rF   r8   r8   r8   r9   r      s   	           r   c                   @   s\   e Zd ZdZejeedddededdZ	ej
edd	Zejed
d	ZdddZdS )ChordCounterzChord synchronisation.r   r   TGroup IDz$Celery ID for the Chord header groupr   zIJSON serialized list of task result tuples. use .group_result() to decode)r   zFStarts at len(chord header) and decrements after each task is finishedNc                    s&   t | j fddt| jD  dS )zReturn the GroupResult of self.

        Arguments:
        ---------
            app (Celery): app instance to create the GroupResult with.

        c                    s   g | ]}t | d qS )appr   ).0rrQ   r8   r9   
<listcomp>   s   z-ChordCounter.group_result.<locals>.<listcomp>rQ   )CeleryGroupResultgroup_idjsonloads	sub_tasks)rC   rR   r8   rQ   r9   group_result   s    

zChordCounter.group_result)N)r3   r4   r5   r6   r   rG   rH   r   r7   rW   rI   rZ   ZPositiveIntegerFieldcountr[   r8   r8   r8   r9   rO      s,   	rO   c                   @   s   e Zd ZdZejeedddededdZ	ej
deded	d
Zej
dededdZejdededdZejdededdZejdddededdZdd Zdd Ze ZG dd dZdS ) r   zTask Group result/status.r   r   TrP   z$Celery ID for the Group that was runr   r#   z7Datetime field when the group result was created in UTCr$   r%   z2Datetime field when the group was completed in UTCr&   r   r   r   r   r   r   r   NFr   r    r!   c                 C   s   | j | j| jdS )NrW   r?   r1   r]   rB   r8   r8   r9   rD      s    zGroupResult.as_dictc                 C   s   d| j  dS )Nz<Group: >)rW   rB   r8   r8   r9   rF      s    zGroupResult.__str__c                   @   sF   e Zd ZdZdgZedZedZej	dgddej	dgd	dgZ
d
S )zGroupResult.Metar(   r)   zgroup resultzgroup resultsr0   Zdjango_cele_date_cr_bd6c1d_idxr+   r1   Zdjango_cele_date_do_caae0e_idxNr2   r8   r8   r8   r9   r:      s   r:   )r3   r4   r5   r6   r   rG   rH   r   r7   rW   rM   r0   r1   rK   rL   rI   r?   rD   rF   r
   ZGroupResultManagerrN   r:   r8   r8   r8   r9   r      sT   
  r   )r6   rX   Zceleryr   Zcelery.resultr   rV   r   Zdjango.confr   Z	django.dbr   Zdjango.utils.translationr   r7    r
   sortedZ
ALL_STATESziprJ   ZModelr   rO   r8   r8   r8   r9   <module>   s   
t)