
    >iV2                         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e      Z  G d dejB                        Z" G d de      Z# G d de      Z$ e        Z% e"       Z& e#       Z' e$       Z(ejR                  jU                  d      Z+	 	 	 dldZ, ejZ                  eddi       ej\                  dd e ed            ee'dd       ej\                  dd edddd!"       ej\                  d#d$e ej^                         d% dd&'       ej\                  d(d)d*eedd+       ej\                  d,d-d.e ejB                  d/      dd0       ej\                  d1e0d2d3 edd45       ej\                  d6d7e0d8d9 ed:d;5       ej\                  d<d=d>e&ed:d?@       ej\                  dAdBdCdded:dDE       ej\                  dFe1ed:dGH       ej\                  dIe1ed:dJH       ej\                  dKe0ed:dLH       ej\                  dMe0ed:dNH       ej\                  dOdPdedQR       ej\                  dSdTe
edQU       ej\                  dVdWe
edQU       ej\                  dXdYe
edQU       ej\                  dZded[R       ej\                  d\ded[R       ej\                  d]ded[R       ej\                  d^e0ed[U       ej\                  d_e(ed[U       ej\                  d`dae%eddbc       ej\                  dddedfdg edbh       ej\                  diedbj      ejd                  e	 	 dmdk                                                                                                                                                                                                    Z3y)nz/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 Zy)
CeleryBeatzCelery Beat flag.beatc                 l    |j                   j                  j                  r|r| j                  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ctxs       m/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/celery/bin/worker.pyconvertzCeleryBeat.convert   s/    77;;!!eII F G     N__name__
__module____qualname____doc__namer#    r$   r"   r   r      s    Dr$   r   c                   0     e Zd ZdZdZ fdZ fdZ xZS )WorkersPoolzWorkers pool option.poolc                 H    t         |   t        j                                y)z=Initialize the workers pool option with the relevant choices.N)super__init__r   get_available_pool_names)r   	__class__s    r"   r1   zWorkersPool.__init__(   s    ==?@r$   c                 V   t        |t              rt        |t              r|S t        |   |||      }|j                  j                  j                  j                  }|dk(  r|rt        j                  |      }|S t        j                  |      }|st        j                  |      }|S )Nprefork)
isinstancetype
issubclassr   r0   r#   r   r   confworker_poolr   get_implementation)r   r   r    r!   r:   r3   s        r"   r#   zWorkersPool.convert,   s     eT"z%'BLuc2ggkk&&22I+  22;?E   2259E#66{Cr$   )r&   r'   r(   r)   r*   r1   r#   __classcell__)r3   s   @r"   r-   r-   #   s    DA r$   r-   c                       e Zd ZdZdZd Zy)HostnamezHostname option.hostnamec                 *    t        t        |            S N)r   r   r   s       r"   r#   zHostname.convertG   s    +E233r$   Nr%   r+   r$   r"   r>   r>   B   s    D4r$   r>   c                       e Zd ZdZdZd Zy)	AutoscalezAutoscaling parameter.z<min workers>, <max workers>c           
         |j                  d      }t        |      dkD  r| j                  dt        |       d       t        |      dk(  r	 t        |d         df}	 t        t        t        t        t        |                        S # t        $ r | j                  d| d       Y Lw xY w# t        $ r' | j                  d|j                  d       d       Y y w xY 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   s       r"   r#   zAutoscale.convertP   s    C u:>II  ZL	3 4 u:?HU1X*	9&S%"9:;;	  H		5eWIFGH
  	9II "ZZ_-Y8 9	9s$   B	 *B- 	B*)B*--CCNr%   r+   r$   r"   rC   rC   K   s     )D9r$   rC   
C_FAKEFORKFc           
         t         rdn|}t        ||      }t        |||||||d      5  	 |
|
} t        j                  | | g|z          t
        cddd       S # t        $ re |	ddlm} |}	|	j                  j                  d||       t        j                  d	d
j                  | g|z         d       t        cY cddd       S w xY w# 1 sw Y   yxY w)zDetach program by argv.rG   F)after_forkersNr   )current_appERROR)r?   zCan't exec %r T)exc_info)rQ   r   r   osexecvr   	ExceptionceleryrT   logsetup_logging_subsystemloggercriticalrP   r   )pathargvlogfilepidfileuidgidumaskworkdirfaker   
executabler?   rT   s                r"   detachrj   l   s     1D
 '8,G	'7CeWd %
' 	%!HHTD6D=)   	{.!GG++8 , 5OOOSXXtftm-D%)  + 	 s)   C
#AA"C;C
CC

C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).)defaultrl   r7   
help_grouphelp-D--detachz%Start worker as a background process.)rl   is_flagrn   ro   rp   z-Sz	--statedbc                 ^    |xs* | j                   j                  j                  j                  S rA   )r   r   r9   worker_state_dbr!   _r   s      r"   <lambda>rx      s#    >cggkk..>> r$   zPPath to the state database. The extension '.db' may be appended to the filename.)rl   r7   callbackro   rp   z-lz
--loglevelWARNINGzLogging level.z-Oz--optimizationrn   )rn   fairzApply optimization profile.z--prefetch-multiplierz<prefetch multiplier>c                 ^    |xs* | j                   j                  j                  j                  S rA   )r   r   r9   worker_prefetch_multiplierrv   s      r"   rx   rx      s#    Icggkk..II r$   z>Set custom prefetch multiplier value for this worker instance.)r7   metavarry   rl   ro   rp   z-cz--concurrencyz<concurrency>c                 ^    |xs* | j                   j                  j                  j                  S rA   )r   r   r9   worker_concurrencyrv   s      r"   rx   rx      s#    Acggkk..AA r$   zPool OptionszlNumber of child processes processing the queue.  The default is the number of CPUs available on your system.z-Pz--poolr5   zPool implementation.)rn   r7   rl   ro   rp   z-Ez--task-eventsz--eventszdSend task-related events that can be captured by monitors like celery events, celerymon, and others.)rs   rn   rl   ro   rp   z--time-limitz;Enables a hard time limit (in seconds int/float) for tasks.)r7   rl   ro   rp   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)rs   rl   ro   z--queuesz-Q)r7   rl   ro   z--exclude-queuesz-Xz	--includez-Iz--without-gossipFeaturesz--without-minglez--without-heartbeatz--heartbeat-intervalz--autoscalez-Bz--beatzEmbedded Beat Options)r7   rl   rs   ro   z-sz--schedule-filenamez
--schedulec                 ^    |xs* | j                   j                  j                  j                  S rA   )r   r   r9   beat_schedule_filenamerv   s      r"   rx   rx   !  s#    Ecggkk..EE r$   )ry   rl   ro   z--scheduler)rl   ro   c
                 H   	 | j                   j                  }| j                  r	 |j                  | j                  d       |
j                  dd      rdd	gt        j                  d
d z   }d|v r|j                  d       d|v r|j                  d       d|v r|j                  d       d|v r|j                  d       t        t        j                  ||||||
j                  dd      |
j                  dd      ||
j                  dd      |      S t        ||        |j                  d||||t!        ||      t!        |	|      | j                   j"                  | j                   j$                  d|
}|j'                          | j)                  |j*                         y# t        t
        f$ r}t        j                  d| |       d}~ww xY w# t,        $ rC}| j                   j/                  |j                  d          | j)                  d
       Y d}~yd}~ww xY 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!   Nrj   Fz-mr[   rG   rr   rq   z--uidz--gidrf   rg   ri   )	rb   rc   rd   re   rf   rg   r   ri   r?   )rd   re   )r?   pool_clsloglevelrb   rc   statedbno_colorquietr   r+   )r   r   argsconfig_from_cmdlineKeyErrorrK   click
UsageErrorgetsysra   removerj   ri   r   Workerr   r   r   startexitexitcoder   error)r!   r?   r   r   rd   re   r   rb   rc   r   kwargsera   r   s                 r"   r   r      s   f-ggkk88-''H'E ::h&(#chhqrl2DT!J't|D!$G$$G$#..")")!s &

7D 9"(**Y"=!%+ZZd%C#+	- 	- 	#3/ 822WW%%''--  	!K j) -&& c#(+- --L  affQi sB   "G F$ CG BG $G3GGG 	H!9HH!)
NNNNNNFNNN)	NNNNNNNNN)4r)   rX   r   r   r   click.typesr   r[   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&   r^   r   Choicer-   r>   rC   CELERY_BEATWORKERS_POOLHOSTNAME	AUTOSCALEenvironr   rQ   rj   commandoptionPathrJ   floatpass_contextr   r+   r$   r"   <module>r      s   5 	 
   ' 5 5 , + O O ' M M	H	
 
%,, >4 49	 92 l}:K	ZZ^^L)
 8<?C%)8 &!3T :<d!"24"89)LM d):< d5::<?)/0 d)#% d5<< 34)02 %-J)/0 d%B'&
' d')+ d'AB n'7	8 !'7	8 %'C	D &'(		) i(	*
 j'(	*
  '(	*
 k'(	*
  #%  #% ##' $#' m#' d02 d#F02 m02 FJ>B>  222	'	'	'	%	%****	)D88B+
'02%0<M<D>r$   