o
    ›¨ÊhV2  ã                    @   sŒ  d Z ddlZddlZddl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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 ddlmZmZmZ eeƒZG dd„ deƒZ G dd„ dej!ƒZ"G dd„ deƒZ#G dd„ deƒZ$e ƒ Z%e"ƒ Z&e#ƒ Z'e$ƒ Z(ej) *d¡Z+			dodd„Z,ej-eddid�ej.ddeedƒƒee'ddd�ej.d d!edddd"d#�ej.d$d%ee /¡ d&d'„ dd(d)�ej.d*d+d,eedd-d�ej.d.d/d0ee !d1¡dd2d�ej.d3e0d4d5d'„ edd6d7�ej.d8d9e0d:d;d'„ ed<d=d7�ej.d>d?d@e&ed<dAdB�ej.dCdDdEdded<dFdG�ej.dHe1ed<dIdJ�ej.dKe1ed<dLdJ�ej.dMe0ed<dNdJ�ej.dOe0ed<dPdJ�ej.dQdRdedSdT�ej.dUdVe
edSdW�ej.dXdYe
edSdW�ej.dZd[e
edSdW�ej.d\ded]dT�ej.d^ded]dT�ej.d_ded]dT�ej.d`e0ed]dW�ej.dae(ed]dW�ej.dbdce%edddde�ej.dfdgdhdid'„ edddj�ej.dkedddl�ej2e		dpdmdn„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒZ3dS )qz/Program used to start a Celery worker instance.é    N)Ú	ParamType)ÚStringParamType)Úconcurrency)ÚCOMMA_SEPARATED_LISTÚ	LOG_LEVELÚCeleryDaemonCommandÚCeleryOptionÚhandle_preload_options)ÚBasePool)ÚSecurityError)Ú
EX_FAILUREÚEX_OKÚdetachedÚmaybe_drop_privileges)Ú
get_logger)Údefault_nodenameÚhost_formatÚnode_formatc                   @   ó   e Zd ZdZdZdd„ ZdS )Ú
CeleryBeatzCelery Beat flag.Úbeatc                 C   s   |j jjr|r|  d¡ |S )NzR-B option does not work on Windows.  Please run celery beat as a separate service.)ÚobjÚappÚ
IS_WINDOWSÚfail©ÚselfÚvalueÚparamÚctx© r    úC/var/www/html/env/lib/python3.10/site-packages/celery/bin/worker.pyÚconvert   s   
zCeleryBeat.convertN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Únamer"   r    r    r    r!   r      ó    r   c                       s0   e Zd ZdZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚWorkersPoolzWorkers pool option.Úpoolc                    s   t ƒ  t ¡ ¡ dS )z=Initialize the workers pool option with the relevant choices.N)ÚsuperÚ__init__r   Úget_available_pool_names)r   ©Ú	__class__r    r!   r-   (   s   zWorkersPool.__init__c                    sj   t |tƒrt|tƒr|S tƒ  |||¡}|jjjj	}|dkr'|r't
 |¡}|S t
 |¡}|s3t
 |¡}|S )NÚprefork)Ú
isinstanceÚtypeÚ
issubclassr
   r,   r"   r   r   ÚconfÚworker_poolr   Úget_implementation)r   r   r   r   r6   r/   r    r!   r"   ,   s   

û
zWorkersPool.convert)r$   r%   r&   r'   r(   r-   r"   Ú__classcell__r    r    r/   r!   r*   #   s
    r*   c                   @   r   )ÚHostnamezHostname option.Úhostnamec                 C   s   t t|ƒƒS ©N)r   r   r   r    r    r!   r"   G   s   zHostname.convertNr#   r    r    r    r!   r9   B   r)   r9   c                   @   r   )Ú	AutoscalezAutoscaling parameter.z<min workers>, <max workers>c              	   C   s¸   |  d¡}t|ƒdkr|  dt|ƒ› d�¡ t|ƒdkr9z
t|d ƒdf}W n ty8   |  d|› d�¡ Y nw zttttt|ƒƒƒƒW S  ty[   |  d| 	d¡› d�¡ Y d S w )	Nú,é   z9Expected two comma separated integers or one integer.Got z	 instead.é   r   zExpected an integer. Got z*Expected two comma separated integers.Got )
ÚsplitÚlenr   ÚintÚ
ValueErrorÚtupleÚreversedÚsortedÚmapÚjoinr   r    r    r!   r"   P   s$   

ÿÿÿÿzAutoscale.convertNr#   r    r    r    r!   r<   K   r)   r<   Ú
C_FAKEFORKFc              
   C   sâ   t rdn|}t||ƒ}t|||||||dd��P z|
dur|
} t | | g| ¡ tW W  d  ƒ S  tyf   |	du rDddlm} |}	|	j	j
d||d� tjd	d
 | g| ¡dd� t Y W  d  ƒ S w 1 sjw   Y  dS )zDetach program by argv.r?   F)Úafter_forkersNr   )Úcurrent_appÚERROR)r:   zCan't exec %rú T)Úexc_info)rI   r   r   ÚosÚexecvr   Ú	ExceptionÚceleryrK   ÚlogÚsetup_logging_subsystemÚloggerÚcriticalrH   r   )ÚpathÚargvÚlogfileÚpidfileÚuidÚgidÚumaskÚworkdirÚfaker   Ú
executabler:   rK   r    r    r!   Údetachl   s2   
ÿúÿÿñùra   Úallow_extra_argsT)ÚclsÚcontext_settingsz-nz
--hostnamezWorker Optionsz]Set custom hostname (e.g., 'w1@%%h').  Expands: %%h (hostname), %%n (name) and %%d, (domain).)Údefaultrc   r3   Ú
help_groupÚhelpú-Dú--detachz%Start worker as a background process.)rc   Úis_flagre   rf   rg   z-Sz	--statedbc                 C   ó   |p| j jjjS r;   )r   r   r5   Úworker_state_db©r   Ú_r   r    r    r!   Ú<lambda>�   ó   ro   zPPath to the state database. The extension '.db' may be appended to the filename.)rc   r3   Úcallbackrf   rg   z-lz
--loglevelÚWARNINGzLogging level.z-Oz--optimizationre   )re   ÚfairzApply optimization profile.z--prefetch-multiplierz<prefetch multiplier>c                 C   rk   r;   )r   r   r5   Úworker_prefetch_multiplierrm   r    r    r!   ro   ³   rp   z>Set custom prefetch multiplier value for this worker instance.)r3   Úmetavarrq   rc   rf   rg   z-cz--concurrencyz<concurrency>c                 C   rk   r;   )r   r   r5   Úworker_concurrencyrm   r    r    r!   ro   ½   rp   zPool OptionszlNumber of child processes processing the queue.  The default is the number of CPUs available on your system.z-Pz--poolr1   zPool implementation.)re   r3   rc   rf   rg   z-Ez--task-eventsz--eventszdSend task-related events that can be captured by monitors like celery events, celerymon, and others.)rj   re   rc   rf   rg   z--time-limitz;Enables a hard time limit (in seconds int/float) for tasks.)r3   rc   rf   rg   z--soft-time-limitz;Enables a soft time limit (in seconds int/float) for tasks.z--max-tasks-per-childzfMaximum number of tasks a pool worker can execute before it's terminated and replaced by a new worker.z--max-memory-per-childa  Maximum amount of resident memory, in KiB, that may be consumed by a child process before it will be replaced by a new one.  If a single task causes a child process to exceed this limit, the task will be completed and the child process will be replaced afterwards.
Default: no limit.z--purgez	--discardzQueue Options)rj   rc   rf   z--queuesz-Q)r3   rc   rf   z--exclude-queuesz-Xz	--includez-Iz--without-gossipÚFeaturesz--without-minglez--without-heartbeatz--heartbeat-intervalz--autoscalez-Bz--beatzEmbedded Beat Options)r3   rc   rj   rf   z-sz--schedule-filenamez
--schedulec                 C   rk   r;   )r   r   r5   Úbeat_schedule_filenamerm   r    r    r!   ro   !  rp   )rq   rc   rf   z--scheduler)rc   rf   c
                 K   s˜  zª| j j}| jr+z
|j| jdd� W n ttfy* } z
tjd|› �| d�‚d}~ww |
 dd¡r}dd	gt	j
d
d…  }d|v rE| d¡ d|v rN| d¡ d|v rW| d¡ d|v r`| d¡ tt	j||||||
 dd¡|
 dd¡||
 dd¡|d�W S t||d� |jd||||t||ƒt|	|ƒ| j j| j jdœ|
¤Ž}| ¡  |  |j¡ W dS  tyË } z| j  |jd ¡ |  d
¡ W Y d}~dS d}~ww )a*  Start worker instance.

    
    Examples
    --------

    
    $ celery --app=proj worker -l INFO
    $ celery -A proj worker -l INFO -Q hipri,lopri
    $ celery -A proj worker --concurrency=4
    $ celery -A proj worker --concurrency=1000 -P eventlet
    $ celery worker --autoscale=10,0

    Úworker)Ú	namespacez?Unable to parse extra configuration from command line.
Reason: )r   Nra   Fz-mrR   r?   ri   rh   z--uidz--gidr]   r^   r`   )	rY   rZ   r[   r\   r]   r^   r   r`   r:   )r[   r\   )r:   Úpool_clsÚloglevelrY   rZ   ÚstatedbÚno_colorÚquietr   r    )r   r   ÚargsÚconfig_from_cmdlineÚKeyErrorrC   ÚclickÚ
UsageErrorÚgetÚsysrX   Úremovera   r`   r   ÚWorkerr   r~   r   ÚstartÚexitÚexitcoder   Úerror)r   r:   r{   r   r[   r\   r|   rY   rZ   r}   ÚkwargsÚerX   ry   r    r    r!   ry   ˆ   sl    4ÿþ€þ






÷úù€þry   )
NNNNNNFNNN)	NNNNNNNNN)4r'   rO   r†   rƒ   r   Úclick.typesr   rR   r   Úcelery.bin.baser   r   r   r   r	   Úcelery.concurrency.baser
   Úcelery.exceptionsr   Úcelery.platformsr   r   r   r   Úcelery.utils.logr   Úcelery.utils.nodenamesr   r   r   r$   rU   r   ÚChoicer*   r9   r<   ÚCELERY_BEATÚWORKERS_POOLÚHOSTNAMEÚ	AUTOSCALEÚenvironr…   rI   ra   ÚcommandÚoptionÚPathrB   ÚfloatÚpass_contextry   r    r    r    r!   Ú<module>   s�   	
þÿ
úúù	úúù	øúù	üüüü
üüüüýýýýýûúþFÿ