o
    _J@h-  ã                   @   sT   d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
 G dd„ deƒZdS )é    N)ÚThreadPoolExecutor)Úconvert_yielded)ÚBaseExecutorÚrun_coroutine_jobÚrun_job)Úiscoroutinefunction_partialc                       s6   e Zd ZdZd	‡ fdd„	Z‡ fdd„Zdd„ Z‡  ZS )
ÚTornadoExecutorak  
    Runs jobs either in a thread pool or directly on the I/O loop.

    If the job function is a native coroutine function, it is scheduled to be run directly in the
    I/O loop as soon as possible. All other functions are run in a thread pool.

    Plugin alias: ``tornado``

    :param int max_workers: maximum number of worker threads in the thread pool
    é
   c                    s   t ƒ  ¡  t|ƒ| _d S ©N)ÚsuperÚ__init__r   Úexecutor)ÚselfÚmax_workers©Ú	__class__© úP/var/www/html/venv/lib/python3.10/site-packages/apscheduler/executors/tornado.pyr      s   
zTornadoExecutor.__init__c                    s   t ƒ  ||¡ |j| _d S r
   )r   ÚstartZ_ioloop)r   Z	schedulerÚaliasr   r   r   r      s   zTornadoExecutor.startc                    s^   ‡ ‡fdd„}t ˆ jƒrtˆ ˆ j|ˆjjƒ}nˆj tˆ ˆ j|ˆjj¡}t	|ƒ}| 
|¡ d S )Nc                    sT   z|   ¡ }W n ty    ˆjˆ jgt ¡ dd … ¢R Ž  Y d S w ˆ ˆ j|¡ d S )Né   )ÚresultÚBaseExceptionZ_run_job_errorÚidÚsysÚexc_infoZ_run_job_success)ÚfÚevents©Újobr   r   r   Úcallback   s   &ÿz0TornadoExecutor._do_submit_job.<locals>.callback)r   Úfuncr   Z_jobstore_aliasZ_loggerÚnamer   Zsubmitr   r   Zadd_done_callback)r   r   Z	run_timesr    r   r   r   r   Ú_do_submit_job   s   
ÿÿzTornadoExecutor._do_submit_job)r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   Ú__classcell__r   r   r   r   r   
   s
    r   )r   Úconcurrent.futuresr   Ztornado.genr   Zapscheduler.executors.baser   r   r   Zapscheduler.utilr   r   r   r   r   r   Ú<module>   s    