o
    i                      @   s$  d 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mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" e# e$edd Z%e%& ej'dddddej(dddedd Z)e%& ej'dddddej'dde*dej(dddedd  Z+e%& ej'd!d"e,d#d$ej'd%d&dd'dej'd(d)dd*dej'd+d,dd-dej'd.d/dd0dej(ddded1d2 Z-e%& ej'd3d4e.d5ed6d7 Ze%& ed8d9 Ze%& ej'dd:d;d<d=ej'd>d?d@ej'dAdBd@ej'dCdDd@ej'dEdFd@ej'dGdHd@ej'dIdJddKej'dLdMd@ej'dNddOdej'dPdQde.dRej'dSdTde.dgdUej'dVdWd@ej'dXdYd@ej'dZdd[de(d\ej(d]dded^d_ Z/e0d`kre%  dS dS )az
RQ command line tool
    N)ConnectionError)Retry)__version__)parse_function_argsparse_schedulepass_cli_configrefresh	show_bothshow_queuesshow_workers)InvalidJobOperationError)	JobStatus)blue)FailedJobRegistryclean_registries)resume)suspend)get_call_string)clean_worker_registryc                   C   s   dS )zRQ command line tool.N r   r   r   A/home/app/Keep/.python/lib/python3.10/site-packages/rq/cli/cli.pymain!   s   r   z--allz-aTzEmpty all queues)Zis_flaghelpqueues)nargsc                    sz   |r j j j j jd}n
 fdd|D }|s&td td |D ]}|	 }t| d|j
 d q(dS )	zEmpty given queues.)
connection	job_classdeath_penalty_class
serializerc                    s"   g | ]} j | j jd qS )r   r   r   )queue_classr   r   ).0queue
cli_configr   r   r   
<listcomp>7   s    zempty.<locals>.<listcomp>Nothing to dor   z jobs removed from z queueN)r!   allr   r   r   clickechosysexitemptyname)r%   r(   r   r   optionsr#   Znum_jobsr   r$   r   r-   (   s"   

r-   zRequeue all failed jobsz--queue)requiredtypejob_idsc           
   
   K   s   t || j| j|d}|r| }|std td tdt| d d}t	|!}|D ]}	z|
|	 W q1 tyG   |d7 }Y q1w W d   n1 sRw   Y  |dkrhtjd| d	d
d dS dS )zRequeue failed jobs.r    r'   r   zRequeueing z jobs from failed queue   NzUnable to requeue z jobs from failed job registryred)Zfg)r   r   r   Zget_job_idsr)   r*   r+   r,   lenZprogressbarrequeuer   Zsecho)
r%   r#   r(   r   r   r2   r/   Zfailed_job_registryZ
fail_countjob_idr   r   r   r6   G   s,   

r6   z
--intervalz-iz3Updates stats every N seconds (default: don't poll))r1   r   z--rawz-rz)Print only the raw numbers, no bar chartsz--only-queuesz-QzShow only queue infoz--only-workersz-WzShow only worker infoz
--by-queuez-RzShows workers by queuec              
   K   s   |rt }n|r
t}nt}z;|r"g }	|D ]}
|	| j|
| jd qn| jj| jd}	|	D ]
}t| t| q,t	|||	||| j| j
| j W dS  tyd } zt| td W Y d}~dS d}~w tyv   t  td Y dS w )zRQ command-line monitor.)r   r3   Nr   )r
   r   r	   appendr!   r   r(   r   r   r   Zworker_classr   r)   r*   r+   r,   KeyboardInterrupt)r%   intervalrawZonly_queuesZonly_workersZby_queuer   r/   funcqsZ
queue_namer#   er   r   r   infof   s4   


r?   z
--durationzBSeconds you want the workers to be suspended.  Default is forever.)r   r1   c                 K   s\   |dur|dk rt d td t| j| |r'd| d}t | dS t d dS )z/Suspends all workers, to resume run `rq resume`Nr3   z*Duration must be an integer greater than 1zSuspending workers for zb seconds. No new jobs will be started during that time, but then will
        automatically resumezUSuspending workers.  No new jobs will be started.  But current jobs will be completed)r)   r*   r+   r,   connection_suspendr   )r%   durationr/   msgr   r   r   r      s   

r   c                 K   s   t | j td dS )zCResumes processing of queues, that were suspended with `rq suspend`zResuming workers.N)connection_resumer   r)   r*   )r%   r/   r   r   r   r      s   
r   z-qzThe name of the queue.default)r   rD   z	--timeoutzWSpecifies the maximum runtime of the job before it is interrupted and marked as failed.)r   z--result-ttlz>Specifies how long successful jobs and their results are kept.z--ttlzDSpecifies the maximum queued time of the job before it is discarded.z--failure-ttlz(Specifies how long failed jobs are kept.z--descriptionz!Additional description of the jobz--depends-onzKSpecifies another job id that must complete before this job will be queued.)r   multiplez--job-idzThe id of this jobz
--at-frontz@Will place the job at the front of the queue, instead of the endz--retry-maxzMaximum amount of retries)r   rD   r1   z--retry-intervalz#Interval between retries in seconds)r   rE   r1   rD   z--schedule-inz8Delay until the function is enqueued (e.g. 10s, 5m, 2d).z--schedule-atzpSchedule job to be enqueued at a certain time formatted in ISO 8601 without timezone (e.g. 2021-05-27T21:45:00).z--quietzOnly logs errors.function	argumentsc                 K   s   t |\}}t|||}|p|}d}|
dkrt|
|}t||}| j||| jd}|du r?||||||||||||	d|}n|||||||||||dtj	|}|
|| |sjtdt| d|j d dS dS )z$Enqueues a job from the command lineNr   )r   r   z	Enqueued z with job-id 'z'.)r   r   r   r   r!   r   Zenqueue_callZ
create_jobr   Z	SCHEDULEDZschedule_jobr)   r*   r   id)r%   r#   timeoutZ
result_ttlttlZfailure_ttldescriptionZ
depends_onr7   Zat_frontZ	retry_maxZretry_intervalZschedule_inZschedule_atquietr   rF   rG   r/   argskwargsZfunction_stringretryZscheduleZjobr   r   r   enqueue   sV   0

"rP   __main__)1__doc__r+   r)   Zredis.exceptionsr   Zrqr   r   versionZrq.cli.helpersr   r   r   r   r	   r
   r   Zrq.exceptionsr   Zrq.jobr   Zrq.logutilsr   Zrq.registryr   r   Zrq.suspensionr   rC   r   r@   Zrq.utilsr   Zrq.worker_registrationr   groupZversion_optionr   commandoptionargumentr-   strr6   floatr?   intrP   __name__r   r   r   r   <module>   s    $!,
H
