vegdZddlZddlZddlZddlZddlmZmZmZddlm Z m Z m Z ddl m Z mZddlmZddlmZdd lmZdd lmZd d lmZmZmZmZmZmZd d lmZd dl m!Z!m"Z"m#Z#e!GddeZ$dS)z- This module contains RequestProcessor class N)datetime timedeltatimezone)ThreadRLockcurrent_thread)CallableAny) AutoTracer)Common) DecisionMaker)StatisticsSender) session_scopesetup_database RequestResultcleanup_old_datarestore_databaseis_malformed_database)SSAError) singleton url_splitswitch_schedstatsceZdZdZdZdfd ZedZdefdZ dd Z dd Z d e de fd ZddefdZdZdZededefdZdZddZdeddfdZxZS)RequestProcessorz^ SSA Request processor implementation. Only one instance is allowed to be created dNcttjd|_|jdt td|r|n t|_ t|_ t||_ t|_t!||_|g|_dS)N req_processorzProcessor enabled: %sTenabled)engine)super__init__logging getLoggerloggerinfo __package__rrr"r_lockrdecision_makerrsenderr auto_tracerstart_background_routine_buffer)selfr" __class__s L/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/modules/processor.pyr$zRequestProcessor.__init__)s '88  0+>>>$'''' &>,T[999(A(A$+(N(NOOO ((n*,,14999K$$L&((-t555OOD$8999K$$G&((-t555OOD$4555K$$J&((-t555"__T-@AAFK$$D&((-t555%T[111OODOV<<<&d3333""2&&&&**4;777A 8r3actionc  ||S#t$rZtj\}}}|jdt |||dt jiYdSwxYw)zACall requested Callable with given args and capture any exceptionz%s failed with exception %s, %sorig_traceback)extraN) Exceptionsysexc_infor' exceptionr; traceback format_exc)r0rSargsetev_s r2rNzRequestProcessor._safe_exec~s T64=  T T T IBA K ! !"C"%f++r2)99;O;Q;Q(R " T T T T T T TsA A+*A+to_sleepc|jdtj|t j|dS)zP Log and sleep given number of seconds or 15 minutes by default z%[%s] Routine thread sleeping for (%s)N)r'r(rrDtimesleep)r0rbs r2rPzRequestProcessor._simple_sleepsE @')). : : : 8r3ctdt|z }|t|dS)zF Sleep the number of minutes remaining till next hour r )hours)minutesN)r total_secondsrPint)r0 start_minute sleep_fors r2rQz&RequestProcessor._sleep_till_next_hoursYQ''') +"+"+""#0=??  3y>>*****r3cd|j5t|ddddS#1swxYwYdSN)r*r)r0r"s r2rMz%RequestProcessor.restore_db_with_locks| Z % % V $ $ $ % % % % % % % % % % % % % % % % % %s %)) timestampcJtj|tjjS)zN Takes an hour of a day, to which the given timestamp belongs )r fromtimestamprrIrK)ros r2get_interval_forz!RequestProcessor.get_interval_fors %i>>CCr3c|j5|jdd}g|_dddn #1swxYwY||dSrn)r*r/ flush_buffer)r0objectss r2rOz RequestProcessor.flush_with_locks Z  l111oGDL                '"""""s +//c||j}|sdSt|j5}||ddddS#1swxYwYdS)z6 Save in-memory buffer into database. N)r/rr"bulk_save_objects)r0rudbs r2rtzRequestProcessor.flush_buffers ?lG  F 4; ' ' *2   ) ) ) * * * * * * * * * * * * * * * * * *sAA  A datac`|s.|jdtjdS|d}||r|jd|dSt|\}}|jdtjg}|j5|j t|||d|d|d|j k|d|d |d |d  t|j |jkr|j dd}g|_ ||dddn #1swxYwY|jd tjdS)z, Process given request data z [%s] has empty request, skippingNurlz %s ignoredz-[%s] Acquires lock to handle request countersrodurationhitting_limitsthrottled_timeio_throttled_time wordpress) domainpathror|is_slow_requestr}r~rrz-[%s] Released lock to handle request counters)r'r(rrDget is_ignoreddebugrr*r/appendrr6len BUFFER_SIZErt)r0ryr{ruriobjects_per_threads r2handlezRequestProcessor.handles  K  ?AQAQAV W W W Fhhuoo ??3    K  lC 0 0 0 Fnn  I(**/ 1 1 1 Z 2 2 L  !";/!*-$($4t7O$O#'(8#9#'(8#9&*+>&?";/       4<  D$444%)\!!!_"!   0 1 1 1+ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2. I(**/ 1 1 1 1 1s?B,E77E;>E;rn)r>N)ra)__name__ __module__ __qualname____doc__rr$propertyr6dictr=r.rBr r rNrjrPrQrM staticmethodrrrOrtr __classcell__)r1s@r2rr s K(00X0EEEEE9999&8&8&8&8PTTSTTTTc+++%%%DCDCDDD\D ### * * * *)14)1D)1)1)1)1)1)1)1)1r3r)%rr%rXrdr[rrr threadingrrrtypingr r autotracerr commonr r+r stat_senderrrxrrrrrrinternal.exceptionsrinternal.utilsrrrrr3r2rs 22222222223333333333 """"""))))))))))))xxxxxxxxxxxxxxxx****** ~1~1~1~1~1v~1~1 ~1~1~1r3