mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Rename 'webhooks' REDIS config to 'tasks'
This commit is contained in:
parent
9e45cafac4
commit
3590ed378d
@ -46,9 +46,9 @@ DATABASE = {
|
|||||||
[Redis](https://redis.io/) is an in-memory data store similar to memcached. While Redis has been an optional component of
|
[Redis](https://redis.io/) is an in-memory data store similar to memcached. While Redis has been an optional component of
|
||||||
NetBox since the introduction of webhooks in version 2.4, it is required starting in 2.6 to support NetBox's caching
|
NetBox since the introduction of webhooks in version 2.4, it is required starting in 2.6 to support NetBox's caching
|
||||||
functionality (as well as other planned features). In 2.7, the connection settings were broken down into two sections for
|
functionality (as well as other planned features). In 2.7, the connection settings were broken down into two sections for
|
||||||
webhooks and caching, allowing the user to connect to different Redis instances/databases per feature.
|
task queuing and caching, allowing the user to connect to different Redis instances/databases per feature.
|
||||||
|
|
||||||
Redis is configured using a configuration setting similar to `DATABASE` and these settings are the same for both of the `webhooks` and `caching` subsections:
|
Redis is configured using a configuration setting similar to `DATABASE` and these settings are the same for both of the `tasks` and `caching` subsections:
|
||||||
|
|
||||||
* `HOST` - Name or IP address of the Redis server (use `localhost` if running locally)
|
* `HOST` - Name or IP address of the Redis server (use `localhost` if running locally)
|
||||||
* `PORT` - TCP port of the Redis service; leave blank for default port (6379)
|
* `PORT` - TCP port of the Redis service; leave blank for default port (6379)
|
||||||
@ -61,7 +61,7 @@ Example:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
REDIS = {
|
REDIS = {
|
||||||
'webhooks': {
|
'tasks': {
|
||||||
'HOST': 'redis.example.com',
|
'HOST': 'redis.example.com',
|
||||||
'PORT': 1234,
|
'PORT': 1234,
|
||||||
'PASSWORD': 'foobar',
|
'PASSWORD': 'foobar',
|
||||||
@ -84,9 +84,9 @@ REDIS = {
|
|||||||
If you are upgrading from a version prior to v2.7, please note that the Redis connection configuration settings have
|
If you are upgrading from a version prior to v2.7, please note that the Redis connection configuration settings have
|
||||||
changed. Manual modification to bring the `REDIS` section inline with the above specification is necessary
|
changed. Manual modification to bring the `REDIS` section inline with the above specification is necessary
|
||||||
|
|
||||||
!!! note
|
!!! warning
|
||||||
It is highly recommended to keep the webhook and cache databases separate. Using the same database number on the
|
It is highly recommended to keep the task and cache databases separate. Using the same database number on the
|
||||||
same Redis instance for both may result in webhook processing data being lost during cache flushing events.
|
same Redis instance for both may result in queued background tasks being lost during cache flushing events.
|
||||||
|
|
||||||
### Using Redis Sentinel
|
### Using Redis Sentinel
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ Example:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
REDIS = {
|
REDIS = {
|
||||||
'webhooks': {
|
'tasks': {
|
||||||
'SENTINELS': [('mysentinel.redis.example.com', 6379)],
|
'SENTINELS': [('mysentinel.redis.example.com', 6379)],
|
||||||
'SENTINEL_SERVICE': 'netbox',
|
'SENTINEL_SERVICE': 'netbox',
|
||||||
'PASSWORD': '',
|
'PASSWORD': '',
|
||||||
@ -126,7 +126,7 @@ REDIS = {
|
|||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
It is possible to have only one or the other Redis configurations to use Sentinel functionality. It is possible
|
It is possible to have only one or the other Redis configurations to use Sentinel functionality. It is possible
|
||||||
for example to have the webhook use sentinel via `HOST`/`PORT` and for caching to use Sentinel via
|
for example to have the tasks database use sentinel via `HOST`/`PORT` and for caching to use Sentinel via
|
||||||
`SENTINELS`/`SENTINEL_SERVICE`.
|
`SENTINELS`/`SENTINEL_SERVICE`.
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ Redis is a in-memory key-value store required as part of the NetBox installation
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
REDIS = {
|
REDIS = {
|
||||||
'webhooks': {
|
'tasks': {
|
||||||
'HOST': 'redis.example.com',
|
'HOST': 'redis.example.com',
|
||||||
'PORT': 1234,
|
'PORT': 1234,
|
||||||
'PASSWORD': 'foobar',
|
'PASSWORD': 'foobar',
|
||||||
|
@ -21,11 +21,11 @@ DATABASE = {
|
|||||||
'CONN_MAX_AGE': 300, # Max database connection age
|
'CONN_MAX_AGE': 300, # Max database connection age
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
|
# Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate
|
||||||
# Seperate sections for webhooks and caching allow for connecting to seperate Redis instances/datbases if desired.
|
# configuration exists for each. Full connection details are required in both sections, and it is strongly recommended
|
||||||
# Full connection details are required in both sections, even if they are the same.
|
# to use two separate database IDs.
|
||||||
REDIS = {
|
REDIS = {
|
||||||
'webhooks': {
|
'tasks': {
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
'PORT': 6379,
|
'PORT': 6379,
|
||||||
# Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
|
# Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
|
||||||
|
@ -178,31 +178,40 @@ if STORAGE_CONFIG and STORAGE_BACKEND is None:
|
|||||||
# Redis
|
# Redis
|
||||||
#
|
#
|
||||||
|
|
||||||
if 'webhooks' not in REDIS:
|
# Background task queuing
|
||||||
raise ImproperlyConfigured(
|
if 'tasks' in REDIS:
|
||||||
"REDIS section in configuration.py is missing webhooks subsection."
|
TASKS_REDIS = REDIS['tasks']
|
||||||
|
elif 'webhooks' in REDIS:
|
||||||
|
# TODO: Remove support for 'webhooks' name in v2.9
|
||||||
|
warnings.warn(
|
||||||
|
"The 'webhooks' REDIS configuration section has been renamed to 'tasks'. Please update your configuration as "
|
||||||
|
"support for the old name will be removed in a future release."
|
||||||
)
|
)
|
||||||
if 'caching' not in REDIS:
|
TASKS_REDIS = REDIS['webhooks']
|
||||||
|
else:
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"REDIS section in configuration.py is missing the 'tasks' subsection."
|
||||||
|
)
|
||||||
|
TASKS_REDIS_HOST = TASKS_REDIS.get('HOST', 'localhost')
|
||||||
|
TASKS_REDIS_PORT = TASKS_REDIS.get('PORT', 6379)
|
||||||
|
TASKS_REDIS_SENTINELS = TASKS_REDIS.get('SENTINELS', [])
|
||||||
|
TASKS_REDIS_USING_SENTINEL = all([
|
||||||
|
isinstance(TASKS_REDIS_SENTINELS, (list, tuple)),
|
||||||
|
len(TASKS_REDIS_SENTINELS) > 0
|
||||||
|
])
|
||||||
|
TASKS_REDIS_SENTINEL_SERVICE = TASKS_REDIS.get('SENTINEL_SERVICE', 'default')
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Caching
|
||||||
|
if 'caching' in REDIS:
|
||||||
|
CACHING_REDIS = REDIS['caching']
|
||||||
|
else:
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"REDIS section in configuration.py is missing caching subsection."
|
"REDIS section in configuration.py is missing caching subsection."
|
||||||
)
|
)
|
||||||
|
|
||||||
WEBHOOKS_REDIS = REDIS.get('webhooks', {})
|
|
||||||
WEBHOOKS_REDIS_HOST = WEBHOOKS_REDIS.get('HOST', 'localhost')
|
|
||||||
WEBHOOKS_REDIS_PORT = WEBHOOKS_REDIS.get('PORT', 6379)
|
|
||||||
WEBHOOKS_REDIS_SENTINELS = WEBHOOKS_REDIS.get('SENTINELS', [])
|
|
||||||
WEBHOOKS_REDIS_USING_SENTINEL = all([
|
|
||||||
isinstance(WEBHOOKS_REDIS_SENTINELS, (list, tuple)),
|
|
||||||
len(WEBHOOKS_REDIS_SENTINELS) > 0
|
|
||||||
])
|
|
||||||
WEBHOOKS_REDIS_SENTINEL_SERVICE = WEBHOOKS_REDIS.get('SENTINEL_SERVICE', 'default')
|
|
||||||
WEBHOOKS_REDIS_PASSWORD = WEBHOOKS_REDIS.get('PASSWORD', '')
|
|
||||||
WEBHOOKS_REDIS_DATABASE = WEBHOOKS_REDIS.get('DATABASE', 0)
|
|
||||||
WEBHOOKS_REDIS_DEFAULT_TIMEOUT = WEBHOOKS_REDIS.get('DEFAULT_TIMEOUT', 300)
|
|
||||||
WEBHOOKS_REDIS_SSL = WEBHOOKS_REDIS.get('SSL', False)
|
|
||||||
|
|
||||||
|
|
||||||
CACHING_REDIS = REDIS.get('caching', {})
|
|
||||||
CACHING_REDIS_HOST = CACHING_REDIS.get('HOST', 'localhost')
|
CACHING_REDIS_HOST = CACHING_REDIS.get('HOST', 'localhost')
|
||||||
CACHING_REDIS_PORT = CACHING_REDIS.get('PORT', 6379)
|
CACHING_REDIS_PORT = CACHING_REDIS.get('PORT', 6379)
|
||||||
CACHING_REDIS_SENTINELS = CACHING_REDIS.get('SENTINELS', [])
|
CACHING_REDIS_SENTINELS = CACHING_REDIS.get('SENTINELS', [])
|
||||||
@ -569,20 +578,20 @@ SWAGGER_SETTINGS = {
|
|||||||
|
|
||||||
RQ_QUEUES = {
|
RQ_QUEUES = {
|
||||||
'default': {
|
'default': {
|
||||||
'HOST': WEBHOOKS_REDIS_HOST,
|
'HOST': TASKS_REDIS_HOST,
|
||||||
'PORT': WEBHOOKS_REDIS_PORT,
|
'PORT': TASKS_REDIS_PORT,
|
||||||
'DB': WEBHOOKS_REDIS_DATABASE,
|
'DB': TASKS_REDIS_DATABASE,
|
||||||
'PASSWORD': WEBHOOKS_REDIS_PASSWORD,
|
'PASSWORD': TASKS_REDIS_PASSWORD,
|
||||||
'DEFAULT_TIMEOUT': WEBHOOKS_REDIS_DEFAULT_TIMEOUT,
|
'DEFAULT_TIMEOUT': TASKS_REDIS_DEFAULT_TIMEOUT,
|
||||||
'SSL': WEBHOOKS_REDIS_SSL,
|
'SSL': TASKS_REDIS_SSL,
|
||||||
} if not WEBHOOKS_REDIS_USING_SENTINEL else {
|
} if not TASKS_REDIS_USING_SENTINEL else {
|
||||||
'SENTINELS': WEBHOOKS_REDIS_SENTINELS,
|
'SENTINELS': TASKS_REDIS_SENTINELS,
|
||||||
'MASTER_NAME': WEBHOOKS_REDIS_SENTINEL_SERVICE,
|
'MASTER_NAME': TASKS_REDIS_SENTINEL_SERVICE,
|
||||||
'DB': WEBHOOKS_REDIS_DATABASE,
|
'DB': TASKS_REDIS_DATABASE,
|
||||||
'PASSWORD': WEBHOOKS_REDIS_PASSWORD,
|
'PASSWORD': TASKS_REDIS_PASSWORD,
|
||||||
'SOCKET_TIMEOUT': None,
|
'SOCKET_TIMEOUT': None,
|
||||||
'CONNECTION_KWARGS': {
|
'CONNECTION_KWARGS': {
|
||||||
'socket_connect_timeout': WEBHOOKS_REDIS_DEFAULT_TIMEOUT
|
'socket_connect_timeout': TASKS_REDIS_DEFAULT_TIMEOUT
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user