
§Ñ®h-  ã               @   sr   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
 Gd d „  d e ƒ Z d S)é    N)ÚThreadPoolExecutor)Úconvert_yielded)ÚBaseExecutorÚrun_coroutine_jobÚrun_job)Úiscoroutinefunction_partialc                   sI   e  Z d  Z d Z d ‡  f d d † Z ‡  f d d †  Z d d „  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  ƒ  j ƒ  t | ƒ |  _ d  S)N)ÚsuperÚ__init__r   Úexecutor)ÚselfÚmax_workers)Ú	__class__© úo/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/apscheduler/executors/tornado.pyr      s    zTornadoExecutor.__init__c                s#   t  ƒ  j | | ƒ | j |  _ d  S)N)r
   ÚstartÚ_ioloop)r   Ú	schedulerÚalias)r   r   r   r      s    zTornadoExecutor.startc                s‰   ‡  ‡ f d d †  } t  ˆ  j ƒ rE t ˆ  ˆ  j | ˆ j j ƒ } n' ˆ j j t ˆ  ˆ  j | ˆ j j ƒ } t	 | ƒ } | j
 | ƒ d  S)Nc                s_   y |  j  ƒ  } Wn5 t k
 rG ˆ j ˆ  j t j ƒ  d d  … Œ Yn Xˆ j ˆ  j | ƒ d  S)Né   )ÚresultÚBaseExceptionÚ_run_job_errorÚidÚsysÚexc_infoÚ_run_job_success)ÚfÚevents)Újobr   r   r   Úcallback   s
    (z0TornadoExecutor._do_submit_job.<locals>.callback)r   Úfuncr   Ú_jobstore_aliasÚ_loggerÚnamer   Úsubmitr   r   Úadd_done_callback)r   r    Ú	run_timesr!   r   r   )r    r   r   Ú_do_submit_job   s    	zTornadoExecutor._do_submit_job)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r)   r   r   )r   r   r   
   s   
r   )r   Úconcurrent.futuresr   Útornado.genr   Úapscheduler.executors.baser   r   r   Úapscheduler.utilr   r   r   r   r   r   Ú<module>   s
   