a
    CgW                     @   s   d dl mZmZ d dlmZ d dlmZ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 d	lmZ d d
lmZmZmZmZ d dlmZ edZedZG dd dedZdS )    )ABCMetaabstractmethod)iscoroutinefunction)AnyIterableTypeVar)sync_to_async)messages)connections)timezone)	ParamSpec)InvalidTaskError)MAX_PRIORITYMIN_PRIORITYTask
TaskResult)is_module_level_functionTPc                   @   s   e Zd ZU eed< eed< eZdZdZ	dZ
eeddddZeedd	d
ZeddddZeeeef ejejee dddZeeef ejejee dddZeedddZeedddZeeej dddZdS )BaseTaskBackendaliasenqueue_on_commitFN)r   paramsreturnc                 C   s<   ddl m} || _t|d|g| _t|dd| _d S )Nr   )DEFAULT_QUEUE_NAMEZQUEUESZENQUEUE_ON_COMMITT)Zdjango_tasksr   r   setgetqueuesboolr   )selfr   r   r    r    Y/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/django_tasks/backends/base.py__init__"   s    zBaseTaskBackend.__init__)taskr   c                 C   s    t js
dS |jdur|jS | jS )z
        Determine the correct `enqueue_on_commit` setting to use for a given task.

        If the task defines it, use that, otherwise, fall back to the backend.
        FN)r
   settingsr   r   r#   r    r    r!   _get_enqueue_on_commit_for_task)   s
    
z/BaseTaskBackend._get_enqueue_on_commit_for_taskc                 C   s   t |jstd| js*t|jr*td|jtk sN|jtksNt|j|jkrbtdt dt | j	sz|j
durztd|j
durt|j
std| jr|j| jvrtd|j d	dS )
zb
        Determine whether the provided task is one which can be executed by the backend.
        z/Task function must be defined at a module levelz$Backend does not support async tasksz(priority must be a whole number between z and Nz"Backend does not support run_afterz#run_after must be an aware datetimezQueue 'z' is not valid for backend)r   funcr   supports_async_taskr   priorityr   r   intsupports_deferZ	run_afterr   Zis_awarer   Z
queue_namer%   r    r    r!   validate_task8   s*    
zBaseTaskBackend.validate_task)r#   argskwargsr   c                 C   s   dS )z0
        Queue up a task to be executed
        Nr    r   r#   r-   r.   r    r    r!   enqueueV   s    zBaseTaskBackend.enqueuec                    s   t | jdd|||dI dH S )H
        Queue up a task function (or coroutine) to be executed
        TZthread_sensitive)r#   r-   r.   N)r   r0   r/   r    r    r!   aenqueue_   s    zBaseTaskBackend.aenqueue)	result_idr   c                 C   s   t ddS )zq
        Retrieve a result by its id (if one exists).
        If one doesn't, raises ResultDoesNotExist.
        z?This backend does not support retrieving or refreshing results.N)NotImplementedErrorr   r4   r    r    r!   
get_resulti   s    zBaseTaskBackend.get_resultc                    s   t | jdd|dI dH S )r1   Tr2   )r4   N)r   r7   r6   r    r    r!   aget_resultr   s    zBaseTaskBackend.aget_result)r.   r   c                 k   s$   | j r tjs tjtjdddV  d S )NzC`ENQUEUE_ON_COMMIT` cannot be used when no databases are configuredz Set `ENQUEUE_ON_COMMIT` to False)hint)r   r
   r$   r	   CheckMessageERROR)r   r.   r    r    r!   checkz   s    zBaseTaskBackend.check)__name__
__module____qualname__str__annotations__r   r   Z
task_classr+   r(   Zsupports_get_resultdictr"   r&   r,   r   r   r   r-   r.   r   r0   r3   r7   r8   r   r   r	   r:   r<   r    r    r    r!   r      s&   
	
	r   )	metaclassN)abcr   r   inspectr   typingr   r   r   Zasgiref.syncr   Zdjango.core.checksr	   Z	django.dbr
   Zdjango.utilsr   Ztyping_extensionsr   Zdjango_tasks.exceptionsr   Zdjango_tasks.taskr   r   r   r   Zdjango_tasks.utilsr   r   r   r   r    r    r    r!   <module>   s   