
    s,g4A                        d Z 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m	Z	m
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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&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl/m1Z2 ddl/m3Z4 ddl5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= erddl-m>Z>  ej~                          ej                  e      d               ZAeAj                          ej                  dddd       ej                  dd      ed                             ZEeAj                          ej                  dddd        ej                  d!deF"       ej                  d#d      ed$                                    ZGeAj                          ej                  d%d&eHd'(       ej                  d)d*dd+       ej                  d,d-dd.       ej                  d/d0dd1       ej                  d2d3dd4       ej                  dd      ed5                                                         ZIeAj                          ej                  d6d7dd8       ej                  d9eFd:d;<       ej                  d=eFed><       ej                  d?eFed@<       ej                  dAdBdCD       ej                  dEeJe!dF<       ej                  dGeJe"dH<       ej                  dIeJe dJ<       ej                  dKeJedL<       ej                  dMddN       ej                  dOdPddQ       ej                  dRdSddT       ej                  dUdVdW       ej                  dXdYD       ej                  dZd[dd\       ej                  d]eJdd^<       ej                  d_eJdd`<       ej                  dadbddc       ej                  dddeddfg       ej                  dhdidjdkg       ej                  dd      edl                                                                                                                                                                  ZKeAj                          ej                  dmdneJo      edp                      Z3eAj                         edq               Z1eAj                          ej                  d!dSdrdjs       ej                  dtduD       ej                  dvdwD       ej                  dxdyD       ej                  dzd{D       ej                  d|d}D       ej                  d~ddW       ej                  ddD       ej                  ddd       ej                  dddeJ       ej                  dddeJdg       ej                  ddD       ej                  ddD       ej                  dRdd       ej                  d       ej                  dd      ed                                                                                                                               ZLeAj                          ej                  d6d7dd8       ej                  ddeFd:d;<       ej                  dOdPddQ       ej                  dRdSddT       ej                  d=eFed><       ej                  d?eFed@<       ej                  deFdd<       ej                  dd       ej                  ddBeJdd<      edeMfd                                                                             ZNeOdk(  r eA        yy)z
RQ command line tool
    N)TYPE_CHECKINGListTypecast)ConnectionError)Retry)__version__)	parse_function_argsparse_schedulepass_cli_configread_config_filerefreshsetup_loghandlers_from_args	show_bothshow_queuesshow_workers)DEFAULT_JOB_MONITORING_INTERVALDEFAULT_LOGGING_DATE_FORMATDEFAULT_LOGGING_FORMAT!DEFAULT_MAINTENANCE_TASK_INTERVALDEFAULT_RESULT_TTLDEFAULT_WORKER_TTL)InvalidJobOperationError)Job	JobStatus)blue)FailedJobRegistryclean_registries)DefaultSerializer)is_suspended)resume)suspend)get_call_stringimport_attribute)Worker)
WorkerPool)clean_worker_registry)
Serializerc                       y)zRQ command line tool.N r*       d/var/www/trellinator.diamondhoofcare.com/public_html/venv/lib/python3.12/site-packages/rq/cli/cli.pymainr-   7   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 ]A  }|j                         }t        j                  dj                  ||j                               C yc c}w )zEmpty given queues.)
connection	job_classdeath_penalty_class
serializerr4   r5   r7   Nothing to dor   z{0} jobs removed from {1} queueN)queue_classallr4   r5   r6   clickechosysexitemptyformatname)
cli_configr;   r0   r7   optionsqueuenum_jobss          r,   r@   r@   >   s     ''++!,, ** * > >!	 , 
  	
  ""*"7"7:CWCWdn # 
 
 

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

4;;HejjQRS
s   0C*zRequeue all failed jobsz--queue)requiredtypejob_idsc                    t        || j                  ||      }|r|j                         }|s*t        j                  d       t        j                  d       t        j                  dj                  t        |                   d}t        j                  |      5 }|D ]  }		 |j                  |	        	 ddd       |dkD  r't        j                  dj                  |      d	       yy# t        $ r |dz  }Y ]w xY w# 1 sw Y   JxY w)
zRequeue failed jobs.r8   r9   r   z%Requeueing {0} jobs from failed queue   Nz3Unable to requeue {0} jobs from failed job registryredfg)r   r4   get_job_idsr<   r=   r>   r?   rA   lenprogressbarrequeuer   secho)
rC   rE   r;   r5   r7   rI   rD   failed_job_registry
fail_countjob_ids
             r,   rR   rR   ]   s     ,*//9Q[ %113

?#	JJ6==c'lKLJ			7	#  w 	 F #++F3	   A~IPPQ[\afg  ,  a
 	   s0   D #C,4D ,C=:D <C==D  D	z
--intervalz-iz3Updates stats every N seconds (default: don't poll))rH   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.)r4   rK   Nr   )r   r   r   appendr:   r4   r;   r   r'   r   worker_classr   r<   r=   r>   r?   KeyboardInterrupt)rC   intervalrawonly_queuesonly_workersby_queuer0   rD   funcqs
queue_namerE   es                r,   inford   |   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--burstz-bz/Run in burst mode (quit after all work is done)z--logging_levelINFOzSet logging level)rH   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/   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--serializerz-Sz!Run worker with custom serializer)rf   r/   z--dequeue-strategyz-dsrf   z5Sets a custom stratey to dequeue from multiple queuesc                    | j                   rt        | j                         ni }|xs |j                  ddg      }|xs |j                  d      }|j                  d      }|rt        j                   j	                  |       |r^t        t        j                  j                  |      d      5 }|j                  t        t        j                                      ddd       | j                  j                  }|dv rC|dk(  rd	nd
}d| d| d}t        j                  |t                t#        j$                  |d       |dvr-t#        j$                  ddd       t'        j(                  d       t+        |	|
||       	 g }|D ]  }|j-                  t/        |              t1        | j2                        r,t#        j$                  dd       t'        j(                  d       |D cg c]+  }| j5                  || j2                  | j6                  |      - }}| j                  ||| j2                  |||||| j6                  | j4                  |xs d|| |      } |	s|
rd}| j9                  ||||||||       y# 1 sw Y   xY wc c}w # t:        $ r4}!t        j<                  |!       t'        j(                  d       Y d}!~!yd}!~!ww xY w)zStarts an RQ worker.QUEUESrf   NAMEDICT_CONFIGwN)RoundRobinWorkerRandomWorkerrn   randomround_robinz	WARNING: z( is deprecated. Use `--dequeue-strategy z
` instead.yellowrM   )rf   ro   rp   zPERROR: Dequeue Strategy can only be one of `default`, `random` or `round_robin`.TrL   )errrN   rK   zBRQ is currently suspended, to resume job execution run "rq resume"r8   )rB   r4   default_worker_ttl
worker_ttldefault_result_ttlmaintenance_intervaljob_monitoring_intervalr5   r:   exception_handlers!disable_default_exception_handlerlog_job_descriptionr7   )burstlogging_leveldate_format
log_formatmax_jobsmax_idle_timewith_schedulerdequeue_strategy)configr   getlogging
dictConfigopenospath
expanduserwritestrgetpidrY   __qualname__warningswarnDeprecationWarningr<   rS   r>   r?   r   rX   r$   r    r4   r:   r5   workr   error)"rC   r{   r|   rB   results_ttlrt   rv   rw   disable_job_desc_loggingverbosequietexception_handlerpidry   r   r   r   r0   r~   r}   r7   r   rD   settingsdict_configfpworker_namestrategy_alternativemsgrx   hrE   workerrc   s"                                     r,   r   r      s   z 7A6G6G
 1 12RH:x||Hyk:F'8<<'D,,}-K!!+.
"''$$S)3/ 	'2HHS%&	' ))66K::+6.+Hxm+&NOcNddnoc-.CH%CC^dhmr	
 	ZH0" 	;A%%&6q&9:	; 
--.KK\afgHHQK  	
  ""*"7"7:CWCWdn # 
 
 ((!,,)!*!5$; **"..19T.O$< <! ) 
$ e M'#!')- 	 		
m	' 	'6
J  as8   --I;?A(J '0JA#J ;JJ 	K
*KK
z
--durationzBSeconds you want the workers to be suspended.  Default is forever.)r/   rH   c                    |/|dk  r*t        j                  d       t        j                  d       t	        | j
                  |       |r'dj                  |      }t        j                  |       yt        j                  d       y)z/Suspends all workers, to resume run `rq resume`NrK   z*Duration must be an integer greater than 1z}Suspending workers for {0} 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_suspendr4   rA   )rC   durationrD   r   s       r,   r"   r"   1  sg     1

?@z,,h7  &x 0 	

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_resumer4   r<   r=   )rC   rD   s     r,   r!   r!   E  s     j++,	JJ"#r+   zThe name of the queue.)r/   rf   z	--timeoutzWSpecifies the maximum runtime of the job before it is interrupted and marked as failed.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.z--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/   rf   rH   z--retry-intervalz#Interval between retries in seconds)r/   rg   rH   rf   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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   )r7   r4   z	Enqueued z with job-id 'z'.)r
   r#   r   r   r:   r4   enqueue_call
create_jobr   	SCHEDULEDschedule_jobr<   r=   r   id)rC   rE   timeout
result_ttlttlfailure_ttldescription
depends_onrV   at_front	retry_maxretry_intervalschedule_inschedule_atr   r7   r   r   rD   argskwargsfunction_stringretryschedulejobs                            r,   enqueuer   M  s   ` 'y1LD&%hf=O0KE1}i0k;7H""5ZJLaLa"bE  
  
 	3)

d?6KSVVTU r+   z--logging-levelz-lz--job-classzDotted path to a Job classz--num-workersrK   zNumber of workers to startr{   c                    | j                   rt        | j                         ni }|xs |j                  ddg      }t        ||||       |rt	        t
        d   t        |            }nt        }|	rt        |	      }	nt        }	|
rt        |
      }
nt        }
|s|rd}t        || j                  |||	|
      }|j                  ||       y)zStarts a RQ worker poolri   rf   r(   N)r4   num_workersr7   rY   r5   )r{   r|   )r   r   r   r   r   r   r$   r   r%   r   r&   r4   start)rC   r{   r|   r0   r7   r   r   r~   r}   rY   r5   r   rD   r   queue_namesserializer_classpools                    r,   worker_poolr     s    6 7A6G6G
 1 12RH#Jx||Hyk'JKZH\ 24DZ4PQ,'5$Y/		 %((#!D 	JJU-J8r+   __main__)P__doc__r   logging.configr   r>   r   typingr   r   r   r   r<   redis.exceptionsr   rqr   r	   versionrq.cli.helpersr
   r   r   r   r   r   r   r   r   rq.defaultsr   r   r   r   r   r   rq.exceptionsr   rq.jobr   r   rq.logutilsr   rq.registryr   r   rq.serializersr   rq.suspensionr    r!   r   r"   r   rq.utilsr#   r$   	rq.workerr%   rq.worker_poolr&   rq.worker_registrationr'   r(   groupversion_optionr-   commandoptionargumentr@   r   rR   floatrd   intr   r   boolr   __name__r*   r+   r,   <module>r      s     	 
  2 2  ,  %
 
 
  3 !  ; , & 5 7 6  % 8) g	  	
 gtT0BC#S  $ D S6 gtT0IJi$S1	$h  % 2 K 
h4 lDu3higtT0[\otT8NOd9PQlD$5MN#  $ O R P ] j B it2cdc6@STn30FMijoC1LStuh#=>oC1CJnon30BIde	-	<	 	+	5	 *D?^_k44FGit2DE#*GRVWgYZ3T4Nvwld9\]c4>uv $;VWndD7Z[%9p #f  $ \ X w ^ x [ X F H ` f p ? v k U e FfR 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 it2cdCFYZk44FGit2DEn30FMijoC1LStum#t:VW#ot#q?[\1919  ] $ X v k F H [ e 19h zF r+   