Edit File: processor.cpython-311.pyc
� ������e������������������������������d�Z�ddlZddlZddlZddlZddlmZmZ�ddlmZm Z m Z �ddlmZm Z �ddlmZ�ddlmZ�dd lmZ�dd lmZ�ddlmZmZmZmZ�dd lmZ�ddlmZmZm Z �e�G�d��de��������������������������Z!dS�)z- This module contains RequestProcessor class �����N)�datetime� timedelta)�Thread�RLock�current_thread)�Callable�Any����)� AutoTracer)�Common)� DecisionMaker)�StatisticsSender����)� session_scope�setup_database� RequestResult�cleanup_old_data)�SSAError)� singleton� url_split�switch_schedstatsc���������������������������e�Zd�ZdZdZd��fd� Zed����������������Zdefd�Z dd �Z dd �Zdede fd�Zddefd�Zd��Zededefd���������������Zd��Zdd�Zdeddfd�Z��xZS�)�RequestProcessorz^ SSA Request processor implementation. Only one instance is allowed to be created �d���Nc������������������������t������������������������������������������������������������t����������j��������d������������|�_��������|�j�����������������������������dt�����������������������t����������d��������������|r|n t������������������������|�_ ��������t������������������������|�_��������t����������|�������������|�_ ��������t������������������������|�_��������t!����������|�������������|�_��������|�������������������������������������g�|�_��������d�S�)N� req_processorzProcessor enabled: %sT��enabled)�engine)�super�__init__�logging� getLogger�logger�info�__package__r���r���r���r����_lockr ����decision_makerr����senderr����auto_tracer�start_background_routine�_buffer)�selfr���� __class__s��� ��L/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/modules/processor.pyr!���zRequestProcessor.__init__)���s�������� ���������'��8�8�������0�+�>�>�>��$�'�'�'�'� &�<�f�f�N�,<�,<����W�W�� �+�6�:�:�:���&�(�(���%�V�4�4�4����%�%�'�'�'�����������c�����������������������|�j���������dz��S�)zp Return config file value multiplied by 1000000, as we receive duration in microseconds i@B�)�requests_duration)r-���s��� r/����configured_durationz$RequestProcessor.configured_duration=���s��������%��/�/r0����reportc����������������������� �|�j������������������������������|�������������dS�#�t����������$�r3}|�j�����������������������������dt����������|�������������������������Y�d}~dS�d}~ww�xY�w)z( Call Statistics Sender zStatisticsSender failed: %sN)r)����sendr���r$����error�str)r-���r4����es��� r/���� send_statszRequestProcessor.send_statsE���sx������ E��K���V�$�$�$�$�$���� E�� E�� E��K���;�S��V�V�D�D�D�D�D�D�D�D�D����� E���s������ A�(A�A�returnc�����������������������t����������|�j��������d�������������}|������������������������������������|�j�����������������������������d|j���������������������dS�)zA Start dumper|DecisionMaker thread in background T)�target�daemonz[%s] Routine startedN)r����background_routine�startr$���r%����name)r-����ts��� r/���r+���z)RequestProcessor.start_background_routineN���sG������� �$�1�$�?�?�?�� ��� � � �����/���8�8�8�8�8r0���c������������������@���� �t����������j����������������������}|j��������dk�����rc|j��������dk�����rA|�j�����������������������������dt ������������������������j��������|�������������|����������������������|�j ���������������������|�j�����������������������������dt ������������������������j��������|�������������|����������������������|�j ���������������������|�j�����������������������������dt ������������������������j��������|�������������|����������������������|�j��������������������}|�j�����������������������������dt ������������������������j��������|�������������t����������|�j ���������������������|����������������������|�j��������|�������������t����������d��������������|����������������������d�������������n|����������������������|j������������������������) z� Dumps collected stats to file once an hour. Runs DecisionMaker once a day Cleanup storage after DecisionMaker run Tr���z2[%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)r����<���)r����now�minute�hourr$���r%���r���rA���� _safe_exec�flush_with_lockr*���r(���r���r���r:���r���� _simple_sleep�_sleep_till_next_hour)r-����tickr4���s��� r/���r?���z#RequestProcessor.background_routineV���s������ 8��<�>�>�D��{�a����9��>�>��K�$�$�L�&�(�(�-�t�5��5��5���O�O�D�$8�9�9�9��K�$�$�G�&�(�(�-�t�5��5��5���O�O�D�$4�5�5�5��K�$�$�J�&�(�(�-�t�5��5��5��"�_�_�T�-@�A�A�F��K�$�$�D�&�(�(�-�t�5��5��5��%�T�[�1�1�1��O�O�D�O�V�<�<�<��&�d�3�3�3�3��"�"�2�&�&�&�&��*�*�4�;�7�7�7�7 8r0����actionc����������� ������������� ��||��S�#�t�����������$�rZ�t����������j����������������������\��}}}|�j�����������������������������dt����������|������������||dt ����������j����������������������i��������������Y�dS�w�xY�w)zACall requested Callable with given args and capture any exceptionz%s failed with exception %s, %s�orig_traceback)�extraN)� Exception�sys�exc_infor$���� exceptionr8���� traceback� format_exc)r-���rM����args�et�ev�_s��� r/���rH���zRequestProcessor._safe_execy���s������� T��6�4�=� ���� T�� T�� T�����I�B��A��K�!�!�"C�"%�f�+�+�r�2�)9�9�;O�;Q�;Q�(R�� "�� T�� T�� T�� T�� T�� T� T���s������A A+�*A+����to_sleepc�����������������������|�j������������������������������dt������������������������j��������|�������������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%���r���rA����time�sleep)r-���r\���s��� r/���rJ���zRequestProcessor._simple_sleep����sE������� ����@�'�)�)�.�� :�� :�� :�� �8�����r0���c�����������������������t����������d�������������t����������|�������������z �������������������������������������}|����������������������t����������|�������������������������dS�)zF Sleep the number of minutes remaining till next hour r ���)�hours)�minutesN)r���� total_secondsrJ����int)r-����start_minute� sleep_fors��� r/���rK���z&RequestProcessor._sleep_till_next_hour����sY��������Q�'�'�'�)� �+"��+"��+"��"�#0�=�?�?�� ����3�y�>�>�*�*�*�*�*r0���� timestampc������������������4�����t����������j��������|�������������j��������S�)zN Takes an hour of a day, to which the given timestamp belongs )r���� fromtimestamprG���)rg���s��� r/����get_interval_forz!RequestProcessor.get_interval_for����s������ ��%�i�0�0�5�5r0���c�����������������������|�j���������5��|�j��������d�d�����������}g�|�_��������d�d�d��������������n#�1�swxY�w�Y���|����������������������|�������������d�S��N)r'���r,����flush_buffer)r-����objectss��� r/���rI���z RequestProcessor.flush_with_lock����s������� �Z�� �� ��l�1�1�1�o�G��D�L� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� �� ���'�"�"�"�"�"s����+�/�/c�����������������������|�|�j���������}|sdS�t����������|�j��������������������5�}|���������������������|�������������ddd�������������dS�#�1�swxY�w�Y���dS�)z6 Save in-memory buffer into database. N)r,���r���r����bulk_save_objects)r-���rn����dbs��� r/���rm���zRequestProcessor.flush_buffer����s���������?��l�G��� ��F� �4�;� '� '�� *�2�� � ��)�)�)� *�� *�� *�� *�� *�� *�� *�� *�� *�� *�� *�� *����� *�� *�� *�� *�� *�� *s����A�A �A �datac������������������`����|s.|�j������������������������������dt������������������������j���������������������dS�|���������������������d������������}|����������������������|������������r|�j������������������������������d|�������������dS�t����������|������������\��}}|�j������������������������������dt������������������������j���������������������g�}|�j��������5��|�j ��������� ��������������������t����������|||d���������|d���������|d���������|�j��������k����|d���������|d ���������|d ���������|d����������� ��� ���������������������t����������|�j ��������������������|�j��������k����r|�j ��������dd����������}g�|�_ ��������ddd�������������n#�1�swxY�w�Y���|����������������������|�������������|�j������������������������������d t������������������������j���������������������dS�)z, Process given request data z [%s] has empty request, skippingN�urlz %s ignoredz-[%s] Acquires lock to handle request countersrg����duration�hitting_limits�throttled_time�io_throttled_time� wordpress) �domain�pathrg���ru����is_slow_requestrv���rw���rx���ry���z-[%s] Released lock to handle request counters)r$���r%���r���rA����get� is_ignored�debugr���r'���r,����appendr���r3����len�BUFFER_SIZErm���)r-���rr���rt���rz����uri�objects_per_threads��� r/����handlezRequestProcessor.handle����s��������� ��K���?��AQ�AQ�AV�W�W�W��F��h�h�u�o�o���?�?�3���� ��K���l�C�0�0�0��F���n�n��������I�(�*�*�/� 1�� 1�� 1��� �Z�� "�� "��L����!��"�;�/�!�*�-�$(��$4�t�7O�$O�#'�(8�#9�#'�(8�#9�&*�+>�&?�"�;�/������ �� �� � ��4�<� � �D�$4�4�4�%)�\�!�!�!�_�"�!���' "�� "�� "�� "�� "�� "�� "�� "�� "�� "�� "����� "�� "�� "�� "�*� ���,�-�-�-�����I�(�*�*�/� 1�� 1�� 1�� 1�� 1s����?BE"�"E&�)E&rl���)r;���N)r[���)�__name__� __module__�__qualname__�__doc__r����r!����propertyr3����dictr:���r+���r?���r���r ���rH���rd���rJ���rK����staticmethodrj���rI���rm���r����� __classcell__)r.���s���@r/���r���r��� ���s|����������������� ��K������������(��0��0���X�0�E���E��E��E��E�9��9��9��9�!8��!8��!8��!8�FT���T�S��T��T��T��T����c���������+��+��+���6�C��6�C��6��6��6���\�6�#��#��#�*��*��*��*�)1�4��)1�D��)1��)1��)1��)1��)1��)1��)1��)1r0���r���)"r����r"���rR���r^���rU���r���r���� threadingr���r���r����typingr���r ���� autotracerr����commonr���r(���r ����stat_senderr���rq���r���r���r���r����internal.exceptionsr����internal.utilsr���r���r���r�����r0���r/����<module>r�������s�������������� � � � ���������������(��(��(��(��(��(��(��(��3��3��3��3��3��3��3��3��3��3�� �� �� �� �� �� �� �� ��"��"��"��"��"��"��������������)��)��)��)��)��)��)��)��)��)��)��)��O��O��O��O��O��O��O��O��O��O��O��O��*��*��*��*��*��*����������������������u1��u1��u1��u1��u1�v��u1��u1����u1��u1��u1r0���