From 5d755a8fb7b77d94a052f10e73c7a98ecb098a0d Mon Sep 17 00:00:00 2001 From: Mehmed Mustafa Date: Wed, 9 Oct 2024 09:17:41 +0200 Subject: [PATCH 1/2] add new env: OCRD_NETWORK_RABBITMQ_HEARTBEAT --- src/ocrd/cli/__init__.py | 2 ++ src/ocrd_network/rabbitmq_utils/connector.py | 4 ++-- src/ocrd_utils/config.py | 16 ++++++++++++++-- tests/network/config.py | 14 ++++++++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ocrd/cli/__init__.py b/src/ocrd/cli/__init__.py index 70d738f083..863b9af0d7 100644 --- a/src/ocrd/cli/__init__.py +++ b/src/ocrd/cli/__init__.py @@ -47,6 +47,8 @@ \b {config.describe('OCRD_NETWORK_RABBITMQ_CLIENT_CONNECT_ATTEMPTS')} \b +{config.describe('OCRD_NETWORK_RABBITMQ_HEARTBEAT')} +\b {config.describe('OCRD_PROFILE_FILE')} \b {config.describe('OCRD_PROFILE', wrap_text=False)} diff --git a/src/ocrd_network/rabbitmq_utils/connector.py b/src/ocrd_network/rabbitmq_utils/connector.py index 893d55a219..8fbbc84ab9 100644 --- a/src/ocrd_network/rabbitmq_utils/connector.py +++ b/src/ocrd_network/rabbitmq_utils/connector.py @@ -6,6 +6,7 @@ from typing import Any, Optional, Union from pika import BasicProperties, BlockingConnection, ConnectionParameters, PlainCredentials from pika.adapters.blocking_connection import BlockingChannel +from ocrd_utils import config from .constants import ( DEFAULT_EXCHANGER_NAME, DEFAULT_EXCHANGER_TYPE, @@ -69,8 +70,7 @@ def open_blocking_connection( port=port, virtual_host=vhost, credentials=credentials, - # TODO: The heartbeat should not be disabled (0)! - heartbeat=0 + heartbeat=config.OCRD_NETWORK_RABBITMQ_HEARTBEAT ), ) return blocking_connection diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index d2cc4efce1..86f3200dd0 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -176,9 +176,21 @@ def _ocrd_download_timeout_parser(val): default=(True, '')) config.add("OCRD_NETWORK_RABBITMQ_CLIENT_CONNECT_ATTEMPTS", - description="Number of attempts for a RabbitMQ client to connect before failing.", + description="Number of attempts for a RabbitMQ client to connect before failing.", + parser=int, + default=(True, 3)) + +config.add( + name="OCRD_NETWORK_RABBITMQ_HEARTBEAT", + description=""" + Controls AMQP heartbeat timeout negotiation during connection tuning. An integer value always overrides the value + proposed by broker. Use 0 to deactivate heartbeats and None to always accept the broker's proposal. If a callable + is given, it will be called with the connection instance and the heartbeat timeout proposed by broker as its + arguments. The callback should return a non-negative integer that will be used to override the broker's proposal. + """, parser=int, - default=(True, 3)) + default=(True, 0) +) config.add(name="OCRD_NETWORK_SOCKETS_ROOT_DIR", description="The root directory where all mets server related socket files are created", diff --git a/tests/network/config.py b/tests/network/config.py index e22cc6ce9d..c316202f1c 100644 --- a/tests/network/config.py +++ b/tests/network/config.py @@ -89,11 +89,21 @@ test_config.add( name="OCRD_NETWORK_RABBITMQ_CLIENT_CONNECT_ATTEMPTS", + description="Number of attempts for a RabbitMQ client to connect before failing", + parser=int, + default=(True, 3) +) + +test_config.add( + name="OCRD_NETWORK_RABBITMQ_HEARTBEAT", description=""" - Number of attempts for a RabbitMQ client to connect before failing + Controls AMQP heartbeat timeout negotiation during connection tuning. An integer value always overrides the value + proposed by broker. Use 0 to deactivate heartbeats and None to always accept the broker's proposal. If a callable + is given, it will be called with the connection instance and the heartbeat timeout proposed by broker as its + arguments. The callback should return a non-negative integer that will be used to override the broker's proposal. """, parser=int, - default=(True, 3) + default=(True, 0) ) test_config.add( From 7f605591ac373664cc225634e22877797fcffb40 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 10 Oct 2024 12:41:57 +0200 Subject: [PATCH 2/2] Simplify description for OCRD_NETWORK_RABBITMQ_HEARTBEAT --- src/ocrd_utils/config.py | 6 ++---- tests/network/config.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index 86f3200dd0..f191389799 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -183,10 +183,8 @@ def _ocrd_download_timeout_parser(val): config.add( name="OCRD_NETWORK_RABBITMQ_HEARTBEAT", description=""" - Controls AMQP heartbeat timeout negotiation during connection tuning. An integer value always overrides the value - proposed by broker. Use 0 to deactivate heartbeats and None to always accept the broker's proposal. If a callable - is given, it will be called with the connection instance and the heartbeat timeout proposed by broker as its - arguments. The callback should return a non-negative integer that will be used to override the broker's proposal. + Controls AMQP heartbeat timeout (in seconds) negotiation during connection tuning. An integer value always overrides the value + proposed by broker. Use 0 to deactivate heartbeat. """, parser=int, default=(True, 0) diff --git a/tests/network/config.py b/tests/network/config.py index c316202f1c..611ad63821 100644 --- a/tests/network/config.py +++ b/tests/network/config.py @@ -97,10 +97,8 @@ test_config.add( name="OCRD_NETWORK_RABBITMQ_HEARTBEAT", description=""" - Controls AMQP heartbeat timeout negotiation during connection tuning. An integer value always overrides the value - proposed by broker. Use 0 to deactivate heartbeats and None to always accept the broker's proposal. If a callable - is given, it will be called with the connection instance and the heartbeat timeout proposed by broker as its - arguments. The callback should return a non-negative integer that will be used to override the broker's proposal. + Controls AMQP heartbeat timeout (in seconds) negotiation during connection tuning. An integer value always overrides the value + proposed by broker. Use 0 to deactivate heartbeat. """, parser=int, default=(True, 0)