관리-도구
편집 파일: persistent_message.cpython-311.pyc
� IMgL � �H � d dl Z d dlZd dlmZ d dlmZ G d� d� � ZdS )� N)�db)� MessageToSendc � � e Zd ZdZdd�Zdd�Zdefd�Zdefd �Z de fd �Zede fd�� � Z ede fd�� � Zdd efd�Zdefd�ZdS )�PersistentMessagesQueuea� The queue to store messages sent to the server if it is unavailable. - stores more recent data; if a limit is exceeded, older messages are deleted. - no duplicate messages are sent NOTE: it is worth remembering that when writing a large number of messages, the amount of memory used may increase by the size of the sqlite cache (this may not be immediately obvious). https://www.sqlite.org/pragma.html#pragma_cache_size � �� Nc �L � || _ || _ g | _ |pt | _ d S �N)� _buffer_limit�_storage_limit�_bufferr �_model)�self�buffer_limit� storage_limit�models �a/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/internals/persistent_message.py�__init__z PersistentMessagesQueue.__init__ s) � �)���+�������,�}����� �returnc � � | j r�t j � � 5 | j � | j � � | j | j z }|dk r| j � |� � g | _ d d d � � d S # 1 swxY w Y d S d S �Nr )r r �atomicr �insert_many�storage_sizer � delete_old)r �need_to_removes r �push_buffer_to_storagez.PersistentMessagesQueue.push_buffer_to_storage s� � ��<� "����� "� "� ��'�'���5�5�5�!%�!2�T�5H�!H��!�A�%�%��K�*�*�>�:�:�:�!��� "� "� "� "� "� "� "� "� "� "� "� "���� "� "� "� "� "� "� "� "s �AA>�>B�Bc � � g }t j � � 5 |t | j � | j j | j j � � � � � � � z }| j � � � � � � d d d � � n# 1 swxY w Y || j z }g | _ t |� � S r )r r �listr �select� timestamp�message�tuples�delete�executer �sorted)r �itemss r �pop_allzPersistentMessagesQueue.pop_all'