• File: processor.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/ssa/modules/__pycache__/processor.cpython-37.pyc
  • Date Modified: 06/05/2023 12:25 PM
  • File size: 6.22 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

edy@sdZddlZddlZddlZddlZddlmZmZddlmZm	Z	m
Z
ddlmZm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZmZmZmZdd
lmZddlmZmZm Z eGdddeZ!dS)z-
This module contains RequestProcessor class
N)datetime	timedelta)ThreadRLockcurrent_thread)CallableAny)
AutoTracer)Common)
DecisionMaker)StatisticsSender)
session_scopesetup_database
RequestResultcleanup_old_data)SSAError)	singleton	url_splitswitch_schedstatscseZdZdZdZd#fdd	ZeddZedd	d
Z	dddd
Z
ddddZee
dddZd$edddZddZeeedddZddZd%ddZedd d!d"ZZS)&RequestProcessorz^
    SSA Request processor implementation.
    Only one instance is allowed to be created
    dNcsxttd|_|jdttdd|r6|nt|_	t
|_t|d|_
t|_t|d|_|g|_dS)NZ
req_processorzProcessor enabled: %sT)enabled)engine)super__init__logging	getLoggerloggerinfo__package__rrrr_lockrdecision_makerr
senderr
auto_tracerstart_background_routine_buffer)selfr)	__class__F/opt/alt/python37/lib/python3.7/site-packages/ssa/modules/processor.pyr)s

zRequestProcessor.__init__cCs
|jdS)zp
        Return config file value multiplied by 1000000,
        as we receive duration in microseconds
        i@B)Zrequests_duration)r(r*r*r+configured_duration=sz$RequestProcessor.configured_duration)reportc
CsJy|j|Wn4tk
rD}z|jdt|Wdd}~XYnXdS)z(
        Call Statistics Sender
        zStatisticsSender failed: %sN)r$sendrrerrorstr)r(r-er*r*r+
send_statsEszRequestProcessor.send_stats)returncCs*t|jdd}||jd|jdS)zA
        Start dumper|DecisionMaker thread in background
        T)targetdaemonz[%s] Routine startedN)rbackground_routinestartrr name)r(tr*r*r+r&Nsz)RequestProcessor.start_background_routinecCsxt}|jdkr|jdkr|jdtj|||j	|jdtj|||j
|jdtj|||j}|jdtj|t|j
||j|tdd|dq||jqWd	S)
z
        Dumps collected stats to file once an hour.
        Runs DecisionMaker once a day
        Cleanup storage after DecisionMaker run
        rz2[%s] Routine thread launching buffer flushing (%s)z-[%s] Routine thread launching AutoTracer (%s)z0[%s] Routine thread launching DecisionMaker (%s)z*[%s] Routine thread launching cleanup (%s)T)r<N)rnowminutehourrr rr8
_safe_execflush_with_lockr%r#rrr2r
_simple_sleep_sleep_till_next_hour)r(Ztickr-r*r*r+r6Vs0



z#RequestProcessor.background_routine)actionr3cGsRy||Stk
rLt\}}}|jjdt|||dtidYnXdS)zACall requested Callable with given args and capture any exceptionz%s failed with exception %s, %sZorig_traceback)extraN)	Exceptionsysexc_infor	exceptionr0	traceback
format_exc)r(rBargsetev_r*r*r+r>ys
zRequestProcessor._safe_exec)to_sleepcCs"|jdtj|t|dS)zP
        Log and sleep given number of seconds or 15 minutes by default
        z%[%s] Routine thread sleeping for (%s)N)rr rr8timesleep)r(rOr*r*r+r@szRequestProcessor._simple_sleepcCs*tddt|d}|t|dS)zF
        Sleep the number of minutes remaining till next hour
        r	)hours)minutesN)r
total_secondsr@int)r(Zstart_minuteZ	sleep_forr*r*r+rAs
z&RequestProcessor._sleep_till_next_hour)	timestampr3cCst|jS)zN
        Takes an hour of a day, to which the given timestamp belongs
        )r
fromtimestampr=)rVr*r*r+get_interval_forsz!RequestProcessor.get_interval_forc	Cs4|j|jdd}g|_WdQRX||dS)N)r"r'flush_buffer)r(objectsr*r*r+r?sz RequestProcessor.flush_with_lockc	Cs:|dkr|j}|sdSt|j}||WdQRXdS)z6
        Save in-memory buffer into database.
        N)r'rrZbulk_save_objects)r(rZdbr*r*r+rYszRequestProcessor.flush_buffer)datar3cCs|d}||r&|jd|dSt|\}}|jdtjg}|jn|j	t
|||d|d|d|jk|d|d|d	|d
d	t|j|j
kr|jdd}g|_WdQRX|||jdtjdS)
z,
        Process given request data
        urlz
%s ignoredNz-[%s] Acquires lock to handle request countersrVdurationhitting_limitsthrottled_timeio_throttled_time	wordpress)	domainpathrVr^Zis_slow_requestr_r`rarbz-[%s] Released lock to handle request counters)getZ
is_ignoredrdebugrrr8r"r'appendrr,lenBUFFER_SIZErY)r(r\r]rcuriZobjects_per_threadr*r*r+handles4



zRequestProcessor.handle)N)rN)N)__name__
__module____qualname____doc__rirpropertyr,dictr2r&r6rrr>rUr@rAstaticmethodrXr?rYrk
__classcell__r*r*)r)r+r s	#


r)"rorrErPrHrr	threadingrrrtypingrrZ
autotracerr
commonrr#rZstat_senderr
r[rrrrinternal.exceptionsrinternal.utilsrrrrr*r*r*r+<module>
s