a
    CgS                     @   s   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 d d	lmZmZ d d
lmZmZmZ d dlmZmZmZ ddlmZ e eZedZedZ G dd deZ!dS )    N)partial)iscoroutinefunction)TypeVar)async_to_sync)transaction)timezone)	ParamSpec)task_enqueuedtask_finished)ResultStatusTask
TaskResult)get_exception_tracebackget_random_idjson_normalize   )BaseTaskBackendTPc                   @   sD   e Zd ZdZeddddZeeef ej	ej
ee dddZdS )	ImmediateBackendTN)task_resultreturnc              
   C   s>  t |dt  tjt| |d |j}t|j	r>t
|j	n|j	}t |dt  z$t |dt||ji |j W n ty } zpt|tr t |dt  t |dt| t |dt| t |dtj tjt| |d W Y d	}~n>d	}~0 0 t |dt  t |dtj tjt| |d d	S )
z[
        Execute the task for the given `TaskResult`, mutating it with the outcome
        enqueued_at)r   
started_atZ_return_valuefinished_atZ
_tracebackZ_exception_classstatusN)object__setattr__r   nowr	   sendtypetaskr   funcr   r   argskwargsBaseException
isinstanceKeyboardInterruptr   r   ZFAILEDr
   Z	SUCCEEDED)selfr   r!   Zcalling_task_funce r*   ^/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/django_tasks/backends/immediate.py_execute_task   s2    
(zImmediateBackend._execute_task)r!   r#   r$   r   c                 C   s^   |  | tt |t tjd d d ||| jd	}| |durPt	t
| j| n
| | |S )N)	r!   idr   r   r   r   r#   r$   backendF)Zvalidate_taskr   r   r   r   ZNEWaliasZ_get_enqueue_on_commit_for_taskr   Z	on_commitr   r,   )r(   r!   r#   r$   r   r*   r*   r+   enqueueD   s     

zImmediateBackend.enqueue)__name__
__module____qualname__Zsupports_async_taskr   r,   r   r   r   r#   r$   r0   r*   r*   r*   r+   r      s
   *r   )"logging	functoolsr   inspectr   typingr   Zasgiref.syncr   Z	django.dbr   Zdjango.utilsr   Ztyping_extensionsr   Zdjango_tasks.signalsr	   r
   Zdjango_tasks.taskr   r   r   Zdjango_tasks.utilsr   r   r   baser   	getLoggerr1   loggerr   r   r   r*   r*   r*   r+   <module>   s   
