Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/configuration/miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,25 @@ This parameter defines the URL of the repository that will be checked for new Ne
Default: `300`

The maximum execution time of a background task (such as running a custom script), in seconds.

---

## RQ_RETRY_INTERVAL

!!! note
This parameter was added in NetBox v3.5.

Default: `60`

This parameter controls how frequently a failed job is retried, up to the maximum number of times specified by `RQ_RETRY_MAX`. This must be either an integer specifying the number of seconds to wait between successive attempts, or a list of such values. For example, `[60, 300, 3600]` will retry the task after 1 minute, 5 minutes, and 1 hour.

---

## RQ_RETRY_MAX

!!! note
This parameter was added in NetBox v3.5.

Default: `0` (retries disabled)

The maximum number of times a background task will be retried before being marked as failed.
5 changes: 3 additions & 2 deletions netbox/core/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from netbox.config import get_config
from netbox.constants import RQ_QUEUE_DEFAULT
from utilities.querysets import RestrictedQuerySet
from utilities.rqworker import get_queue_for_model
from utilities.rqworker import get_queue_for_model, get_rq_retry

__all__ = (
'Job',
Expand Down Expand Up @@ -219,5 +219,6 @@ def trigger_webhooks(self, event):
event=event,
data=self.data,
timestamp=str(timezone.now()),
username=self.user.username
username=self.user.username,
retry=get_rq_retry()
)
4 changes: 3 additions & 1 deletion netbox/extras/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from netbox.constants import RQ_QUEUE_DEFAULT
from netbox.registry import registry
from utilities.api import get_serializer_for_model
from utilities.rqworker import get_rq_retry
from utilities.utils import serialize_object
from .choices import *
from .models import Webhook
Expand Down Expand Up @@ -116,5 +117,6 @@ def flush_webhooks(queue):
snapshots=data['snapshots'],
timestamp=str(timezone.now()),
username=data['username'],
request_id=data['request_id']
request_id=data['request_id'],
retry=get_rq_retry()
)
2 changes: 2 additions & 0 deletions netbox/netbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
REMOTE_AUTH_GROUP_SEPARATOR = getattr(configuration, 'REMOTE_AUTH_GROUP_SEPARATOR', '|')
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
RQ_DEFAULT_TIMEOUT = getattr(configuration, 'RQ_DEFAULT_TIMEOUT', 300)
RQ_RETRY_INTERVAL = getattr(configuration, 'RQ_RETRY_INTERVAL', 60)
RQ_RETRY_MAX = getattr(configuration, 'RQ_RETRY_MAX', 0)
SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/')
SEARCH_BACKEND = getattr(configuration, 'SEARCH_BACKEND', 'netbox.search.backends.CachedValueSearchBackend')
SECURE_SSL_REDIRECT = getattr(configuration, 'SECURE_SSL_REDIRECT', False)
Expand Down
14 changes: 13 additions & 1 deletion netbox/utilities/rqworker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django_rq.queues import get_connection
from rq import Worker
from rq import Retry, Worker

from netbox.config import get_config
from netbox.constants import RQ_QUEUE_DEFAULT

__all__ = (
'get_queue_for_model',
'get_rq_retry',
'get_workers_for_queue',
)

Expand All @@ -22,3 +23,14 @@ def get_workers_for_queue(queue_name):
Returns True if a worker process is currently servicing the specified queue.
"""
return Worker.count(get_connection(queue_name))


def get_rq_retry():
"""
If RQ_RETRY_MAX is defined and greater than zero, instantiate and return a Retry object to be
used when queuing a job. Otherwise, return None.
"""
retry_max = get_config().RQ_RETRY_MAX
retry_interval = get_config().RQ_RETRY_INTERVAL
if retry_max:
return Retry(max=retry_max, interval=retry_interval)