o
    hW                     @   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
	 dededdfddZd	edefd
dZd	eddfddZed	eeef dejdejdee fddZd	eeef dejdejdee fddZdedefddZdedefddZdedeej fddZdS )BaseTaskBackendaliasenqueue_on_commitFparamsreturnNc                 C   s<   ddl m} || _t|d|g| _t|dd| _d S )Nr   )DEFAULT_QUEUE_NAMEQUEUESENQUEUE_ON_COMMITT)django_tasksr   r   setgetqueuesboolr   )selfr   r   r    r#   Z/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/django_tasks/backends/base.py__init__"   s   zBaseTaskBackend.__init__taskc                 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 s'|jtks't|j|jkr1tdt dt | j	s=|j
dur=td|j
durLt|j
sLtd| jr^|j| jvr`td|j d	dS 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_defer	run_afterr   is_awarer    
queue_namer(   r#   r#   r$   validate_task8   s&   


zBaseTaskBackend.validate_taskargskwargsc                 C   s   dS )z0
        Queue up a task to be executed
        Nr#   r"   r&   r3   r4   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thread_sensitive)r&   r3   r4   N)r   r6   r5   r#   r#   r$   aenqueue_   s   zBaseTaskBackend.aenqueue	result_idc                 C   s   t d)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.)NotImplementedErrorr"   r;   r#   r#   r$   
get_resulti   s   zBaseTaskBackend.get_resultc                    s   t | jdd|dI dH S )r7   Tr8   )r;   N)r   r>   r=   r#   r#   r$   aget_resultr   s   zBaseTaskBackend.aget_resultc                 k   s.    | j rtjstjtjdddV  d S d S 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"   r4   r#   r#   r$   checkz   s   zBaseTaskBackend.check)__name__
__module____qualname__str__annotations__r!   r   
task_classr.   r+   supports_get_resultdictr%   r)   r2   r   r   r   r3   r4   r   r6   r:   r>   r?   r   r   r	   rA   rC   r#   r#   r#   r$   r      sF   
 



	r   )	metaclassN)abcr   r   inspectr   typingr   r   r   asgiref.syncr   django.core.checksr	   	django.dbr
   django.utilsr   typing_extensionsr   django_tasks.exceptionsr   django_tasks.taskr   r   r   r   django_tasks.utilsr   r   r   r   r#   r#   r#   r$   <module>   s    