HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/celery/worker/consumer/__pycache__/consumer.cpython-39.pyc
a

X>h�u�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZmZdd	lmZdd
lmZddlmZddlmZmZdd
lmZmZddlmZddl m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:dZ;ej<Z<ej=Z=e<e=hZ>e)e?�Z@e@jAe@jBe@jCe@jDe@jEf\ZAZBZFZDZGdZHdZIdZJdZKdZLdZMdZNd ZOd!ZPd"ZQd#ZRd$d%�ZSGd&d'�d'�ZTGd(d)�d)ejU�ZVdS)*z�Worker Consumer Blueprint.

This module contains the components responsible for consuming messages
from the broker, processing the messages and keeping the broker connections
up and running.
�N)�defaultdict)�sleep)�
restart_state)�RestartFreqExceeded)�	DummyLock)�ContentDisallowed�DecodeError)�_detect_environment)�	safe_repr)�TokenBucket)�ppartial�promise)�	bootsteps�signals)�build_tracer)�CPendingDeprecationWarning�InvalidTaskError�
NotRegistered�WorkerShutdown�WorkerTerminate)�noop)�
get_logger)�gethostname)�Bunch)�truncate)�humanize_seconds�rate)�loops)�active_requests�maybe_shutdown�requests�reserved_requests�
task_reserved)�Consumer�Evloop�	dump_bodyzMconsumer: Connection to broker lost. Trying to re-establish the connection...z0Trying again {when}... ({retries}/{max_retries})z'consumer: Cannot connect to %s: %s.
%s
zWill retry using next failover.zkReceived and deleted unknown message.  Wrong destination?!?

The full contents of the message body was: %s
a�Received unregistered task of type %s.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you're using relative imports?

Please see
https://docs.celeryq.dev/en/latest/internals/protocol.html
for more information.

The full contents of the message body was:
%s

The full contents of the message headers:
%s

The delivery info for this task is:
%s
a
Received invalid task message: %s
The message has been ignored and discarded.

Please ensure your message conforms to the task
message protocol as described here:
https://docs.celeryq.dev/en/latest/internals/protocol.html

The full contents of the message body was:
%s
zICan't decode message body: %r [type:%r encoding:%r headers:%s]

body: %s
zTbody: {0}
{{content_type:{1} content_encoding:{2}
  delivery_info:{3} headers={4}}}
z}Task %s cannot be acknowledged after a connection loss since late acknowledgement is enabled for it.
Terminating it instead.
a�
In Celery 5.1 we introduced an optional breaking change which
on connection loss cancels all currently executed tasks with late acknowledgement enabled.
These tasks cannot be acknowledged as the connection is gone, and the tasks are automatically redelivered
back to the queue. You can enable this behavior using the worker_cancel_long_running_tasks_on_connection_loss
setting. In Celery 5.1 it is set to False by default. The setting will be set to True by default in Celery 6.0.
cCs.|dur|jn|}d�tt|�d�t|j��S)z+Format message body for debugging purposes.Nz{} ({}b)i)�body�formatrr
�len)�mr&�r*�I/usr/local/lib/python3.9/site-packages/celery/worker/consumer/consumer.pyr%�s�r%c@s�eZdZdZeZdZdZdZdZ	dZ
Gdd�dej�Ze
ddddddddddd	fd
d�Zdd
�Zdd�Zdd�Zdd�Zd_dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d`d9d:�Z%dad;d<�Z&d=d>�Z'd?d@�Z(dAdB�Z)dbdCdD�Z*dEdF�Z+dGdH�Z,dIdJ�Z-dKdL�Z.dMdN�Z/dOdP�Z0dQdR�Z1e2fdSdT�Z3dUdV�Z4e5dWdX��Z6e5dYdZ��Z7d[d\�Z8d]d^�Z9dS)cr#�Consumer blueprint.N���Tc@s$eZdZdZdZgd�Zdd�ZdS)zConsumer.Blueprintr,r#)
z,celery.worker.consumer.connection:Connectionz$celery.worker.consumer.mingle:Minglez$celery.worker.consumer.events:Eventsz$celery.worker.consumer.gossip:Gossipz"celery.worker.consumer.heart:Heartz&celery.worker.consumer.control:Controlz"celery.worker.consumer.tasks:Tasksz7celery.worker.consumer.delayed_delivery:DelayedDeliveryz&celery.worker.consumer.consumer:Evloopz"celery.worker.consumer.agent:AgentcCs|�|d�dS)N�shutdown)�send_all)�self�parentr*r*r+r.�szConsumer.Blueprint.shutdownN)�__name__�
__module__�__qualname__�__doc__�nameZ
default_stepsr.r*r*r*r+�	Blueprint�s
r7F��cKs�||_||_||_|pt�|_t��|_||_||_	|�
�|_|j��|_
|j
j|_|j
j|_tddd�|_t�tj�|_d|_||_t�|_|jjj|_||_||_|
|_ d|_!t"dd��|_#|�$�||_%|j%s�t&|jdd	��r|	|_'|j'du�r
|jjj(|_'nd|_'t)|d
��s*|�r"t*j+nt*j,|_-t.�dk�r@d|jj_/g|_0g|_1|j2|jj1d|j3d
�|_4|j4j5|fit6|
�p|ifi|����dS)N�r9)ZmaxRZmaxTrTcSsdS�Nr*r*r*r*r+�<lambda>��z#Consumer.__init__.<locals>.<lambda>Zis_greenF�loopZgeventZconsumer)�steps�on_close)7�app�
controller�
init_callbackr�hostname�os�getpid�pid�pool�timer�
Strategies�
strategies�connection_for_read�conninfo�connection_errors�channel_errorsr�_restart_state�logger�isEnabledFor�logging�INFOZ
_does_info�_limit_order�on_task_request�set�on_task_message�confZbroker_heartbeat_checkrate�amqheartbeat_rate�disable_rate_limits�initial_prefetch_count�prefetch_multiplier�_maximum_prefetch_restoredr�task_buckets�reset_rate_limits�hub�getattr�amqheartbeatZbroker_heartbeat�hasattrrZasynloopZsynloopr>r	Zbroker_connection_timeout�_pending_operationsr?r7r@�	blueprint�apply�dict)r0rVrCrDrHrArIrBrarcZworker_optionsr[r\r]�kwargsr*r*r+�__init__�sP





�zConsumer.__init__cOs8t|g|�Ri|��}|jr(|j�|�S|j�|�|Sr;)rra�	call_soonre�append)r0�p�argsrir*r*r+rk�s
zConsumer.call_soonc
CsT|jsP|jrPz|j���WqtyL}zt�d|�WYd}~qd}~00qdS)NzPending callback raised: %r)rare�pop�	ExceptionrQ�	exception�r0�excr*r*r+�perform_pending_operations�sz#Consumer.perform_pending_operationscCs$tt|dd��}|r t|dd�SdS)NZ
rate_limitr9)�capacity)rrbr)r0�type�limitr*r*r+�bucket_for_task�szConsumer.bucket_for_taskcs&�j��fdd��jj��D��dS)Nc3s |]\}}|��|�fVqdSr;)rx)�.0�n�t�r0r*r+�	<genexpr>sz-Consumer.reset_rate_limits.<locals>.<genexpr>)r_�updaterA�tasks�itemsr|r*r|r+r`s
�zConsumer.reset_rate_limitsrcCs0|jj}|jr|sdS|jj|j|_|�|�S)a�Update prefetch count after pool/shrink grow operations.

        Index must be the change in number of processes as a positive
        (increasing) or negative (decreasing) number.

        Note:
            Currently pool grow operations will end up with an offset
            of +1 if the initial size of the pool was 0 (e.g.
            :option:`--autoscale=1,0 <celery worker --autoscale>`).
        N)rH�
num_processesr\r]�_update_qos_eventually)r0�indexr�r*r*r+�_update_prefetch_counts
�zConsumer._update_prefetch_countcCs&|dkr|jjn|jjt|�|j�S)Nr)�qos�decrement_eventuallyZincrement_eventually�absr])r0r�r*r*r+r�s�zConsumer._update_qos_eventuallycCst|�|�|�dSr;)r"rV)r0�requestr*r*r+�_limit_move_to_pool szConsumer._limit_move_to_poolcCs�z|��\}}Wnty&Yq�Yn0|�|�r@|�|�qq|j�||f�|jdd}|_|�|�}|jj	||j
|f|d�q�qdS)Nr9�
)�priority)ro�
IndexErrorZcan_consumer��contents�
appendleftrUZ
expected_timerIZ
call_after�_schedule_bucket_request)r0�bucketr��tokens�priZholdr*r*r+r�$s




�z!Consumer._schedule_bucket_requestcCs|�||f�|�|�Sr;)�addr��r0r�r�r�r*r*r+�_limit_task<szConsumer._limit_taskcCs"|j��|�||f�|�|�Sr;)r�r�r�r�r�r*r*r+�_limit_post_eta@s
zConsumer._limit_post_etac
Cs�|j}|jtv�r�t�|jrhz|j��Wn:tyf}z"td|dd�t	d�WYd}~n
d}~00|jd7_|j
jjr�|j
|j}n|j
}z|�|�Wq|�y�}z�|j}d|_|�|�}|j
j|}|�std|r�dnd�d|�d	��td�|�t|t��r0|jtjk�r0td
�td�|�t�|jtv�rr|j�rV|�|�n
|�|�|��|�|�WYd}~qd}~00qdS)NzFrequent restarts detected: %rr9��exc_infoFzRetrying to Z	establishzre-establishzX a connection to the message broker after a connection loss has been disabled (app.conf.z=False). Shutting down...z Too many open files. Aborting...)rf�state�STOP_CONDITIONSr�
restart_countrP�stepr�critrrArYZbroker_channel_error_retryrNrO�start�first_connection_attempt�_get_connection_retry_typer�
isinstance�OSError�errno�EMFILEr�
connection�#on_connection_error_after_connected�$on_connection_error_before_connectedr@Zrestart)r0rfrsZrecoverable_errors�is_connection_loss_on_startupZconnection_retry_typeZconnection_retryr*r*r+r�EsJ

��


zConsumer.startcCs|r|jjjdurdSdS)N�"broker_connection_retry_on_startup�broker_connection_retry)rArYr�)r0r�r*r*r+r�ps���z#Consumer._get_connection_retry_typecCstt|j��|d�dS)NzTrying to reconnect...)�error�CONNECTION_ERRORrM�as_urirrr*r*r+r�vs�z-Consumer.on_connection_error_before_connectedc	Cs�ttdd�z|j��Wnty,Yn0|jjjrltt	�D](}|j
jr@|js@tt
|�|�|j�q@nt�tt�|jjjr�t|j|jttt	��|j�|_|j|jk|_|js�t�d|j�dttt	���d|j�d��dS)NTr�z+Temporarily reducing the prefetch count to z to avoid over-fetching since zW tasks are currently being processed.
The prefetch count will be gradually restored to z" as the tasks complete processing.)�warn�CONNECTION_RETRYr�ZcollectrprArYZ3worker_cancel_long_running_tasks_on_connection_loss�tupler�task�	acks_late�acknowledged�3TERMINATING_TASK_ON_RESTART_AFTER_A_CONNECTION_LOSS�cancelrH�warnings�CANCEL_TASKS_BY_DEFAULTr�&worker_enable_prefetch_count_reduction�maxr]�max_prefetch_countr(r\r^rQ�info)r0rsr�r*r*r+r�zs6
�
�

���z,Consumer.on_connection_error_after_connectedcCs|jj|d|fdd�dS)N�register_with_event_loopzHub.register)rn�description)rfr/)r0rar*r*r+r��s�z!Consumer.register_with_event_loopcCs|��|j�|�dSr;)rtrfr.r|r*r*r+r.�szConsumer.shutdowncCs|j�|�dSr;)rf�stopr|r*r*r+r��sz
Consumer.stopcCs|jd}|_|r||�dSr;)rC)r0�callbackr*r*r+�on_ready�szConsumer.on_readyc	Cs(||j|j|j|j|j|j|jj|jf	Sr;)	r��
task_consumerrfrar�rcrAZclockrZr|r*r*r+�	loop_args�s

�zConsumer.loop_argsc	Cs4tt||j|jt|j�t||j�dd�|��dS)a.Callback called if an error occurs while decoding a message.

        Simply logs the error and acknowledges the message so it
        doesn't enter a loop.

        Arguments:
            message (kombu.Message): The message received.
            exc (Exception): The exception being handled.
        r9r�N)	r��MESSAGE_DECODE_ERROR�content_type�content_encodingr
�headersr%r&Zack)r0�messagersr*r*r+�on_decode_error�s

�zConsumer.on_decode_errorcCs�|jr|jjr|jj��|jr*|j��|j��D]}|r4|��q4tD]}|tvrJt|=qJt��|j	r~|j	j
r~|j	�
�dSr;)rBZ	semaphore�clearrIr_�valuesZ
clear_pendingr!r rH�flush)r0r�Z
request_idr*r*r+r@�s

zConsumer.on_closecCs*|j|jd�}|jr&|j�|j|j�|S)z�Establish the broker connection used for consuming tasks.

        Retries establishing the connection if the
        :setting:`broker_connection_retry` setting is enabled
        ��	heartbeat)rLrcra�	transportr�r�)r0�connr*r*r+�connect�szConsumer.connectcCs|�|jj|d��S)Nr�)�ensure_connectedrArL)r0r�r*r*r+rL�s�zConsumer.connection_for_readcCs|�|jj||d��S)N)�urlr�)r�rA�connection_for_write)r0r�r�r*r*r+r��s�zConsumer.connection_for_writecs�tf��fdd�	}d}�jjjdurD�jjj}|rdt�td��n �jrX�jjj}n�jjj}|rz��	�d�_�S�j
|�jjjtd��d�_�S)NcsTt�dd�r|dkrt}|jt|dd�t|d��jjjd�}tt	��
�||�dS)NZaltr�in� r8)�when�retries�max_retries)rb�CONNECTION_FAILOVERr'r�intrArY�broker_connection_max_retriesr�r�r�)rs�intervalZ	next_step�r�r0r*r+�_error_handler�s

�z1Consumer.ensure_connected.<locals>._error_handlerFaThe broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to refrain from retrying connections on startup,
you should set broker_connection_retry_on_startup to False instead.)r�)
�CONNECTION_RETRY_STEPrArYr�r�r�r�rr�r�Zensure_connectionr�r)r0r�r�Zretry_disabledr*r�r+r��s.��
�zConsumer.ensure_connectedcCs|jr|j��dSr;)�event_dispatcherr�r|r*r*r+�
_flush_eventsszConsumer._flush_eventscCs|jr|jj�|j�dSr;)ra�_readyr�r�r|r*r*r+�on_send_event_bufferedszConsumer.on_send_event_bufferedc	Ks�|j}|jjj}||vr"||}n:|dur.|n|}|dur>dn|}|j|f|||d�|��}|�|�s�|�|�|��td|�dS)N�direct)�exchange�
exchange_type�routing_keyzStarted consuming from %s)	r�rA�amqp�queuesZ
select_addZconsuming_fromZ	add_queueZconsumer�)	r0�queuer�r�r��optionsZcsetr��qr*r*r+�add_task_queue!s&

���

zConsumer.add_task_queuecCs*td|�|jjj�|�|j�|�dS)NzCanceling queue %s)r�rAr�r�Zdeselectr�Zcancel_by_queue)r0r�r*r*r+�cancel_task_queue7s
zConsumer.cancel_task_queuecCs t|�|�|�|j��dS)zAMethod called by the timer to apply a task with an ETA/countdown.N)r"rVr�r�)r0r�r*r*r+�apply_eta_task<s
zConsumer.apply_eta_taskcCs0t�t||�t|j�t|j�t|j�t|j��Sr;)�MESSAGE_REPORTr'r%r
r�r��
delivery_infor��r0r&r�r*r*r+�_message_reportBs�zConsumer._message_reportcCs6tt|�||��|�t|j�tjj||dd�dS)N��senderr�rs)	r��UNKNOWN_FORMATr��reject_log_errorrQrNr�
task_rejected�sendr�r*r*r+�on_unknown_messageIszConsumer.on_unknown_messagec	Cs�tt|t||�|j|jdd�z&|jd|jd}}|j�d�}Wn.tyr|j}|d|d}}d}Yn0t|d||j	�d�|j	�d�dd�}|�
t|j�|j
jj|t|�|d	�|jr�|jjd
|d|�d�d
�tjj|||||d�dS)NTr��idr��root_id�correlation_id�reply_to)r6Zchordr�r�r�Zerrbacks�r�ztask-failedzNotRegistered(�))�uuidrq)r�r�rsr6r�)r��UNKNOWN_TASK_ERRORr%r�r��get�KeyError�payloadrZ
propertiesr�rQrNrA�backendZmark_as_failurerr�r�rZtask_unknown)	r0r&r�rsZid_r6r�rr�r*r*r+�on_unknown_taskNs@�


�
�
�
�zConsumer.on_unknown_taskcCs:tt|t||�dd�|�t|j�tjj|||d�dS)NTr�r�)	r��INVALID_TASK_ERRORr%r�rQrNrr�r�)r0r&r�rsr*r*r+�on_invalid_taskos
�zConsumer.on_invalid_taskcCsN|jj}|jj��D]4\}}|�|j|�|j|<t||||j|jd�|_qdS)N)rA)	rA�loaderrr�Zstart_strategyrKrrDZ	__trace__)r0r
r6r�r*r*r+�update_strategiesus�zConsumer.update_strategiescsB�j��j��j��j��j��j���������fdd�}|S)Nc
s�d}z|jd}Wn�ty.�d|�YSty�z|��}Wn4tyz}z��||�WYd}~YSd}~00z|d|}}Wn$ttfy��||�YYS0Yn0z�|}Wn2t�y�}z�d||�WYd}~Sd}~00z���|jf�jd�}��|jf�jd�}�j	�sj�j
dk�rj�j�jk�rj|j
�j�jd�|j
�j�jd�|||||��Wnfttf�y�}z�|||�WYd}~Sd}~0t�y�}z��||�WYd}~Sd}~00dS)Nr�)Zon_errorr)r��	TypeErrorr�decoderpr�Z
ack_log_error�0_restore_prefetch_count_after_connection_restartr�r^r��_new_prefetch_countr�Zthenrrr)r�r�type_rsZstrategyZack_log_error_promiseZreject_log_error_promise�rk�	callbacksr	r�rr
r0rKr*r+�on_task_received�sf&"����
���� z6Consumer.create_task_handler.<locals>.on_task_received)rKr�rr	rXrk)r0r
rr*rr+�create_task_handler|s7zConsumer.create_task_handlercGs�|jj��t|jjj|jf�r0Wd�dSt|j|j	�}||j_
|_|j�|jj
�|j}||jk|_|dur�|jdur�t
�d|j���Wd�n1s�0YdS)NFTzcResuming normal operations following a restart.
Prefetch count has been restored to the maximum of )r��_mutex�anyrArYr�r^�minr�r�valuer\rWrQr�)r0rmrnZnew_prefetch_countZalready_restoredr*r*r+r�s"

���z9Consumer._restore_prefetch_count_after_connection_restartcCs|jj|jSr;)rHr�r]r|r*r*r+r��szConsumer.max_prefetch_countcCs|jj|jSr;)r�rr]r|r*r*r+r�szConsumer._new_prefetch_countcCsdj||j��d�S)z``repr(self)``.z%<Consumer: {self.hostname} ({state})>)r0r�)r'rfZhuman_stater|r*r*r+�__repr__�s
�zConsumer.__repr__cCs4dd�}tt|t��}|r0|D]}|�|j�qdS)z�Cancel all active requests that either do not require late acknowledgments or,
        if they do, have not been acknowledged yet.
        cSs|jjsdS|jsdSdS)NTF)r�r�r�r�r*r*r+�
should_cancel�s
z;Consumer.cancel_all_unacked_requests.<locals>.should_cancelN)r��filterrr�rH)r0rZrequests_to_cancelr�r*r*r+�cancel_all_unacked_requests�s
z$Consumer.cancel_all_unacked_requests)r)N)NN)NNN):r2r3r4r5rhrJrCrHrIr�r�rr7rrjrkrtrxr`r�r�r�r�r�r�r�r�r�r�r�r.r�r�r�r�r@r�rLr�r�r�r�r�r�r�r�r�rr	rr
rr�propertyr�rrrr*r*r*r+r#�sv�
<
+

4�
!A

r#c@s(eZdZdZdZdZdd�Zdd�ZdS)	r$zHEvent loop service.

    Note:
        This is always started last.
    z
event loopTcCs|�|�|j|���dSr;)�	patch_allr>r��r0�cr*r*r+r�s
zEvloop.startcCst�|j_dSr;)rr�rrr*r*r+rszEvloop.patch_allN)r2r3r4r5�label�lastr�rr*r*r*r+r$�s
r$)Wr5r�rSrEr��collectionsr�timerZbilliard.commonrZbilliard.exceptionsrZkombu.asynchronous.semaphorerZkombu.exceptionsrrZkombu.utils.compatr	Zkombu.utils.encodingr
Zkombu.utils.limitsrZvinerr
ZceleryrrZcelery.app.tracerZcelery.exceptionsrrrrrZcelery.utils.functionalrZcelery.utils.logrZcelery.utils.nodenamesrZcelery.utils.objectsrZcelery.utils.textrZcelery.utils.timerrZ
celery.workerrZcelery.worker.staterrr r!r"�__all__ZCLOSEZ	TERMINATEr�r2rQ�debugr��warningr��criticalr�r�r�r�r�r�r�rrr�r�r�r�r%r#Z
StartStopStepr$r*r*r*r+�<module>sf�	r