
    ]j                         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jF                          ejH                  e      d               Z%e%jM                          ejN                  dddd       ejP                  dd      ed                             Z)e%jM                          ejN                  dddd       ejN                  dde*       ejP                  dd      ed                                    Z+e%jM                          ejN                  dde,d !       ejN                  d"d#dd$       ejN                  d%d&dd'       ejN                  d(d)dd*       ejN                  d+d,dd-       ejP                  dd      ed.                                                         Z-e%jM                          ejN                  d/d0e.1      ed2                      Ze%jM                         ed3               Ze%jM                          ejN                  dd4d5d67       ejN                  d8d9:       ejN                  d;d<:       ejN                  d=d>:       ejN                  d?d@:       ejN                  dAdB:       ejN                  dCdDdE       ejN                  dFdG:       ejN                  dHddI       ejN                  dJdKde.L       ejN                  dMdNde.dgO       ejN                  dPdQ:       ejN                  dRdS:       ejN                  dTddU       ejP                  dV       ejP                  dWd      edX                                                                                                                               Z/e0dYk(  r e%        yy)Zz
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                       y)zRQ command line tool.N r       4/root/env/lib/python3.12/site-packages/rq/cli/cli.pymainr   !   s     	r   z--allz-aTzEmpty all queues)is_flaghelpqueues)nargsc           	         |r>| j                   j                  | j                  | j                  | j                  |      }n6|D cg c]+  }| j                  || j                  | j                  |      - }}|s*t        j                  d       t        j                  d       |D ]7  }|j                         }t        j                  | d|j                   d       9 yc c}w )zEmpty given queues.)
connection	job_classdeath_penalty_class
serializerr!   r"   r$   Nothing to dor   z jobs removed from z queueN)queue_classallr!   r"   r#   clickechosysexitemptyname)
cli_configr(   r   r$   optionsqueuenum_jobss          r   r-   r-   (   s     ''++!,, ** * > >!	 , 
  	
  ""*"7"7:CWCWdn # 
 
 

?# G;;=

hZ25::,fEFG
s   0C zRequeue all failed jobsz--queue)requiredtypejob_idsc                     t        || j                  | j                  |      }|r|j                         }|s*t	        j
                  d       t        j                  d       t	        j
                  dt        |       d       d}t	        j                  |      5 }|D ]  }		 |j                  |	        	 ddd       |dkD  rt	        j                  d| d	d
       yy# t        $ r |dz  }Y Rw xY w# 1 sw Y   ?xY w)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)fg)r   r!   r"   get_job_idsr)   r*   r+   r,   lenprogressbarrequeuer   secho)
r/   r1   r(   r"   r$   r5   r0   failed_job_registry
fail_countjob_ids
             r   r=   r=   G   s     ,*//:;O;O\f %113

?#	JJS\N*ABCJ			7	#  w 	 F #++F3	   A~(4RSX]^  ,  a
 	   s0   C4"C 3C4 C1.C40C11C44C=z
--intervalz-iz3Updates stats every N seconds (default: don't poll))r4   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           
      r   |rt         }n|rt        }nt        }	 |r6g }	|D ].  }
|	j                  | j	                  |
| j
                               0 n&| j                  j                  | j
                        }	|	D ]  }t        |       t        |        t        |||	||| j                  | j                  | j
                         y# t        $ r4}t        j                  |       t        j                  d       Y d}~yd}~wt         $ r, t        j                          t        j                  d       Y yw xY w)zRQ command-line monitor.)r!   r7   Nr   )r   r   r
   appendr'   r!   r(   r   r   r	   worker_classr   r)   r*   r+   r,   KeyboardInterrupt)r/   intervalrawonly_queuesonly_workersby_queuer   r0   funcqs
queue_namer1   es                r   inforO   f   s    	B$ `
		*00
H]H]0^_` ''++z7L7L+MB 	)EU#!%(	) 	dBXz/E/EzG^G^`j`u`u	
  

1 

s   B+C 	D6*C>>5D65D6z
--durationzBSeconds you want the workers to be suspended.  Default is forever.)r   r4   c                     |/|dk  r*t        j                  d       t        j                  d       t	        | j
                  |       |rd| d}t        j                  |       yt        j                  d       y)z/Suspends all workers, to resume run `rq resume`Nr7   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/   durationr0   msgs       r   r   r      sf     1

?@z,,h7)( 4  

3

jkr   c                 X    t        | j                         t        j                  d       y)zCResumes processing of queues, that were suspended with `rq suspend`zResuming workers.N)connection_resumer!   r)   r*   )r/   r0   s     r   r   r      s     j++,	JJ"#r   z-qzThe name of the queue.default)r   rV   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   rV   r4   z--retry-intervalz#Interval between retries in seconds)r   rW   r4   rV   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                    t        |      \  }}t        |||      }|xs |}d}|
dkD  rt        |
|      }t        ||      }| j	                  ||| j
                        }||j                  |||||||||||	d|      }n=|j                  ||||||||||dt        j                  |      }|j                  ||       |s0t        j                  dt        |      d|j                  d       yy)z$Enqueues a job from the command lineNr   )r$   r!   z	Enqueued z with job-id 'z'.)r   r   r   r   r'   r!   enqueue_call
create_jobr   	SCHEDULEDschedule_jobr)   r*   r   id)r/   r1   timeout
result_ttlttlfailure_ttldescription
depends_onrA   at_front	retry_maxretry_intervalschedule_inschedule_atquietr$   rX   rY   r0   argskwargsfunction_stringretryschedulejobs                            r   enqueuerr      s   ` 'y1LD&%hf=O0KE1}i0k;7H""5ZJLaLa"bE  
  
 	3)

d?6KSVVTU r   __main__)1__doc__r+   r)   redis.exceptionsr   rqr   r   versionrq.cli.helpersr   r   r   r	   r
   r   r   rq.exceptionsr   rq.jobr   rq.logutilsr   rq.registryr   r   rq.suspensionr   rU   r   rQ   rq.utilsr   rq.worker_registrationr   groupversion_optionr   commandoptionargumentr-   strr=   floatrO   intrr   __name__r   r   r   <module>r      s"     ,  %   3   ; 5 7 $ 8 g	  	
 gtT0BC#G  $ D G6 gtT0IJi$S1	$_  % 2 K 
_4 lDu3higtT0[\otT8NOd9PQlD$5MN#  $ O R P ] j B l!elopl  q l" $  $ i$<iPo n#cdgbco$NOo$GHfqu j34lD/qrm"=qsS 'LW[bepqorso$^_
+
 i,?@
2&EV  '  A ` t T s 5 I P d e Q 4EVP zF r   