From 90dbe9bf60ab3c72be10fd070c65c26dca543ca5 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 23 Sep 2020 13:28:05 -0400 Subject: [PATCH] Closes #5171: Introduce the RQ_DEFAULT_TIMEOUT configuration parameter --- docs/configuration/optional-settings.md | 8 ++++++++ docs/configuration/required-settings.md | 7 ++----- docs/installation/3-netbox.md | 2 -- docs/release-notes/version-2.9.md | 3 +++ netbox/netbox/configuration.example.py | 5 +++-- netbox/netbox/configuration.testing.py | 2 -- netbox/netbox/settings.py | 11 +++++++---- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index 244ffc120..651781c17 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -491,6 +491,14 @@ The file path to the location where custom reports will be kept. By default, thi --- +## RQ_DEFAULT_TIMEOUT + +Default: `300` + +The maximum execution time of a background task (such as running a custom script), in seconds. + +--- + ## SCRIPTS_ROOT Default: `$INSTALL_ROOT/netbox/scripts/` diff --git a/docs/configuration/required-settings.md b/docs/configuration/required-settings.md index d54b13e38..2edf6c7c7 100644 --- a/docs/configuration/required-settings.md +++ b/docs/configuration/required-settings.md @@ -65,7 +65,6 @@ Redis is configured using a configuration setting similar to `DATABASE` and thes * `PORT` - TCP port of the Redis service; leave blank for default port (6379) * `PASSWORD` - Redis password (if set) * `DATABASE` - Numeric database ID -* `DEFAULT_TIMEOUT` - Connection timeout in seconds * `SSL` - Use SSL connection to Redis An example configuration is provided below: @@ -77,7 +76,6 @@ REDIS = { 'PORT': 1234, 'PASSWORD': 'foobar', 'DATABASE': 0, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, }, 'caching': { @@ -85,7 +83,6 @@ REDIS = { 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 1, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, } } @@ -109,6 +106,7 @@ above and the addition of two new keys. * `SENTINELS`: List of tuples or tuple of tuples with each inner tuple containing the name or IP address of the Redis server and port for each sentinel instance to connect to * `SENTINEL_SERVICE`: Name of the master / service to connect to +* `SENTINEL_TIMEOUT`: Connection timeout, in seconds Example: @@ -117,9 +115,9 @@ REDIS = { 'tasks': { 'SENTINELS': [('mysentinel.redis.example.com', 6379)], 'SENTINEL_SERVICE': 'netbox', + 'SENTINEL_TIMEOUT': 10, 'PASSWORD': '', 'DATABASE': 0, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, }, 'caching': { @@ -130,7 +128,6 @@ REDIS = { 'SENTINEL_SERVICE': 'netbox', 'PASSWORD': '', 'DATABASE': 1, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, } } diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md index 235e39a8f..54ecd284a 100644 --- a/docs/installation/3-netbox.md +++ b/docs/installation/3-netbox.md @@ -163,7 +163,6 @@ REDIS = { 'PORT': 6379, # Redis port 'PASSWORD': '', # Redis password (optional) 'DATABASE': 0, # Database ID - 'DEFAULT_TIMEOUT': 300, # Timeout (seconds) 'SSL': False, # Use SSL (optional) }, 'caching': { @@ -171,7 +170,6 @@ REDIS = { 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 1, # Unique ID for second database - 'DEFAULT_TIMEOUT': 300, 'SSL': False, } } diff --git a/docs/release-notes/version-2.9.md b/docs/release-notes/version-2.9.md index fa672a51e..2c7a40ddb 100644 --- a/docs/release-notes/version-2.9.md +++ b/docs/release-notes/version-2.9.md @@ -2,6 +2,8 @@ ## v2.9.4 (FUTURE) +**NOTE:** This release removes support for the `DEFAULT_TIMEOUT` parameter under `REDIS` database configuration. Set `RQ_DEFAULT_TIMEOUT` as a global configuration parameter instead. + ### Enhancements * [#1755](https://github.com/netbox-community/netbox/issues/1755) - Toggle order in which rack elevations are displayed @@ -9,6 +11,7 @@ * [#5134](https://github.com/netbox-community/netbox/issues/5134) - Display full hierarchy in breadcrumbs for sites/racks * [#5149](https://github.com/netbox-community/netbox/issues/5149) - Add rack group field to device edit form * [#5164](https://github.com/netbox-community/netbox/issues/5164) - Show total rack count per rack group under site view +* [#5171](https://github.com/netbox-community/netbox/issues/5171) - Introduce the `RQ_DEFAULT_TIMEOUT` configuration parameter ### Bug Fixes diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index e753dd637..51c73bccc 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -33,7 +33,6 @@ REDIS = { # 'SENTINEL_SERVICE': 'netbox', 'PASSWORD': '', 'DATABASE': 0, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, }, 'caching': { @@ -44,7 +43,6 @@ REDIS = { # 'SENTINEL_SERVICE': 'netbox', 'PASSWORD': '', 'DATABASE': 1, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, } } @@ -232,6 +230,9 @@ RELEASE_CHECK_URL = None # this setting is derived from the installed location. # REPORTS_ROOT = '/opt/netbox/netbox/reports' +# Maximum execution time for background tasks, in seconds. +RQ_DEFAULT_TIMEOUT = 300 + # The file path where custom scripts will be stored. A trailing slash is not needed. Note that the default value of # this setting is derived from the installed location. # SCRIPTS_ROOT = '/opt/netbox/netbox/scripts' diff --git a/netbox/netbox/configuration.testing.py b/netbox/netbox/configuration.testing.py index 09d5362ab..066f94841 100644 --- a/netbox/netbox/configuration.testing.py +++ b/netbox/netbox/configuration.testing.py @@ -24,7 +24,6 @@ REDIS = { 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 0, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, }, 'caching': { @@ -32,7 +31,6 @@ REDIS = { 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 1, - 'DEFAULT_TIMEOUT': 300, 'SSL': False, } } diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 8a8c47c75..3a859c58e 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -110,6 +110,7 @@ REMOTE_AUTH_HEADER = getattr(configuration, 'REMOTE_AUTH_HEADER', 'HTTP_REMOTE_U RELEASE_CHECK_URL = getattr(configuration, 'RELEASE_CHECK_URL', None) RELEASE_CHECK_TIMEOUT = getattr(configuration, 'RELEASE_CHECK_TIMEOUT', 24 * 3600) REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/') +RQ_DEFAULT_TIMEOUT = getattr(configuration, 'RQ_DEFAULT_TIMEOUT', 300) SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/') SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None) SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') @@ -220,10 +221,13 @@ TASKS_REDIS_USING_SENTINEL = all([ len(TASKS_REDIS_SENTINELS) > 0 ]) TASKS_REDIS_SENTINEL_SERVICE = TASKS_REDIS.get('SENTINEL_SERVICE', 'default') +TASKS_REDIS_SENTINEL_TIMEOUT = TASKS_REDIS.get('SENTINEL_TIMEOUT', 10) TASKS_REDIS_PASSWORD = TASKS_REDIS.get('PASSWORD', '') TASKS_REDIS_DATABASE = TASKS_REDIS.get('DATABASE', 0) -TASKS_REDIS_DEFAULT_TIMEOUT = TASKS_REDIS.get('DEFAULT_TIMEOUT', 300) TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False) +# TODO: Remove in v2.10 (see #5171) +if 'DEFAULT_TIMEOUT' in TASKS_REDIS: + warnings.warn('DEFAULT_TIMEOUT is no longer supported under REDIS configuration. Set RQ_DEFAULT_TIMEOUT instead.') # Caching if 'caching' not in REDIS: @@ -241,7 +245,6 @@ CACHING_REDIS_USING_SENTINEL = all([ CACHING_REDIS_SENTINEL_SERVICE = CACHING_REDIS.get('SENTINEL_SERVICE', 'default') CACHING_REDIS_PASSWORD = CACHING_REDIS.get('PASSWORD', '') CACHING_REDIS_DATABASE = CACHING_REDIS.get('DATABASE', 0) -CACHING_REDIS_DEFAULT_TIMEOUT = CACHING_REDIS.get('DEFAULT_TIMEOUT', 300) CACHING_REDIS_SSL = CACHING_REDIS.get('SSL', False) @@ -549,7 +552,7 @@ if TASKS_REDIS_USING_SENTINEL: 'PASSWORD': TASKS_REDIS_PASSWORD, 'SOCKET_TIMEOUT': None, 'CONNECTION_KWARGS': { - 'socket_connect_timeout': TASKS_REDIS_DEFAULT_TIMEOUT + 'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT }, } else: @@ -558,8 +561,8 @@ else: 'PORT': TASKS_REDIS_PORT, 'DB': TASKS_REDIS_DATABASE, 'PASSWORD': TASKS_REDIS_PASSWORD, - 'DEFAULT_TIMEOUT': TASKS_REDIS_DEFAULT_TIMEOUT, 'SSL': TASKS_REDIS_SSL, + 'DEFAULT_TIMEOUT': RQ_DEFAULT_TIMEOUT, } RQ_QUEUES = {