o
    i?                      @   s  d dl Z d dlZ d dlZd dlZd dlZd dlmZmZ d dl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mZmZmZmZmZ d dlmZ d dlmZ d d	lmZ erbd d
lmZ e  ej!dddddej!de"dddej!de"eddej!de"eddej!ddddej!de#eddej!de#eddej!de#ed dej!d!e#ed"dej!d#dd$dej!d%d&dd'dej!d(d)dd*dej!d+d,dd-ej!d.d/dej!d0d1dd2dej!d3e#dd4dej!d5e#dd6dej!d7d8dd9dej!d:d;d<d=d>ej$d?d@dAedBdC Z%e  ej!dddddej!dDdEe"dFddej!d%d&dd'dej!d(d)dd*dej!de"eddej!de"eddej$d?d@dAej!dGde#dHdIdedJe&fdKdLZ'dS )M    N)TYPE_CHECKINGcast)ConnectionError)main)import_attributepass_cli_configread_config_filesetup_loghandlers_from_args)DEFAULT_JOB_MONITORING_INTERVALDEFAULT_LOGGING_DATE_FORMATDEFAULT_LOGGING_FORMAT!DEFAULT_MAINTENANCE_TASK_INTERVALDEFAULT_RESULT_TTLDEFAULT_WORKER_TTL)DefaultSerializer)is_suspended)
WorkerPool)
Serializerz--burstz-bTz/Run in burst mode (quit after all work is done))Zis_flaghelpz--logging_levelzSet logging level)typedefaultr   z--log-formatzSet the format of the logsz--date-formatzSet the date format of the logsz--namez-nzSpecify a different name)r   z--results-ttlz"Default results timeout to be usedz--worker-ttlzWorker timeout to be usedz--maintenance-intervalz1Maintenance task interval (in seconds) to be usedz--job-monitoring-intervalz*Default job monitoring interval to be usedz--disable-job-desc-loggingzTurn off description logging.z	--verbosez-vzShow more outputz--quietz-qzShow less outputz--exception-handlerzException handler(s) to use)r   Zmultiplez--pidz;Write the process ID number to a file at the specified pathz#--disable-default-exception-handlerz-dz&Disable RQ's default exception handlerz
--max-jobsz!Maximum number of jobs to executez--max-idle-timez5Maximum seconds to stay alive without jobs to executez--with-schedulerz-szRun worker with schedulerz--dequeue-strategyz-dsr   z5Sets a custom stratey to dequeue from multiple queues)r   r   queues)nargsc           !         sD   j rt j ni }|p|ddg}|p|d}|d}|r'tj | |rKttj|d}|	t
t  W d   n1 sFw   Y   jj}|dv rq|dkrYd	nd
}d| d| d}t|t tj|dd |dvrtjdddd td t|	|
|| z[g }|D ]	}|t| qt jrtjddd td  fdd|D } j|| j||||| j j|pd|| d}|	rd}n|
rd}|j||||||||d W dS  ty }  zt|  td W Y d} ~ dS d} ~ w ty! }  ztj| dd td W Y d} ~ dS d} ~ ww )zStarts an RQ worker.QUEUESr   NAMEZDICT_CONFIGwN)ZRoundRobinWorkerRandomWorkerr   randomround_robinz	WARNING: z( is deprecated. Use `--dequeue-strategy z
` instead.yellow)fg)r   r   r   zPERROR: Dequeue Strategy can only be one of `default`, `random` or `round_robin`.Tred)errr!      zBRQ is currently suspended, to resume job execution run "rq resume"c                    s"   g | ]} j | j jd qS ))
connection	job_class
serializer)queue_classr%   r&   ).0queue
cli_configr'    E/home/app/Keep/.python/lib/python3.10/site-packages/rq/cli/workers.py
<listcomp>   s    zworker.<locals>.<listcomp>)namer%   Zdefault_worker_ttl
worker_ttlZdefault_result_ttlmaintenance_intervaljob_monitoring_intervalr&   r(   exception_handlers!disable_default_exception_handlerZlog_job_descriptionr'   DEBUGWARNING)burstlogging_leveldate_format
log_formatmax_jobsmax_idle_timewith_schedulerdequeue_strategy)exc_info) configr   getlogging
dictConfigopenospath
expanduserwritestrgetpidworker_class__qualname__warningswarnDeprecationWarningclickZsechosysexitr	   appendr   r   r%   r&   r(   Zworkr   error	Exception)!r,   r8   r9   r0   Zresults_ttlr1   r2   r3   Zdisable_job_desc_loggingverbosequietZexception_handlerpidr5   r<   r=   r>   r   r;   r:   r'   r?   optionssettingsZdict_configfpZworker_nameZstrategy_alternativemsgr4   hZworker_instanceer-   r+   r.   worker"   s   <





r`   z--logging-levelz-lINFOz--num-workersr$   zNumber of workers to startr8   c
                 K   s   | j rt| j ni }|p|ddg}t|||| |r$tdt|}nt}|r+d}n|r/d}t|| j|	|| j	| j
d}|j||d dS )	zStarts a RQ worker poolr   r   r   r6   r7   )r%   num_workersr'   rL   r&   )r8   r9   N)rA   r   rB   r	   r   r   r   r   r%   rL   r&   start)r,   r8   r9   r   r'   rW   rX   r;   r:   rb   rZ   r[   Zqueue_namespoolr-   r-   r.   worker_pool   s&   re   )(rC   logging.configrF   rR   rN   typingr   r   rQ   Zredis.exceptionsr   Z
rq.cli.clir   Zrq.cli.helpersr   r   r   r	   Zrq.defaultsr
   r   r   r   r   r   Zrq.serializersr   Zrq.suspensionr   Zrq.worker_poolr   r   commandoptionrJ   intargumentr`   boolre   r-   r-   r-   r.   <module>   s     4o"