mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Pass a Retry object only if RQ_RETRY_MAX is non-zero
This commit is contained in:
parent
5c404cf604
commit
e3f5c806b8
@ -223,6 +223,6 @@ This parameter controls how frequently a failed job is retried, up to the maximu
|
||||
!!! note
|
||||
This parameter was added in NetBox v3.5.
|
||||
|
||||
Default: `0`
|
||||
Default: `0` (retries disabled)
|
||||
|
||||
The maximum number of times a background task will be retried before being marked as failed.
|
||||
|
@ -9,7 +9,6 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from rq import Retry
|
||||
|
||||
from core.choices import JobStatusChoices
|
||||
from extras.constants import EVENT_JOB_END, EVENT_JOB_START
|
||||
@ -17,7 +16,7 @@ from extras.utils import FeatureQuery
|
||||
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',
|
||||
@ -221,5 +220,5 @@ class Job(models.Model):
|
||||
data=self.data,
|
||||
timestamp=str(timezone.now()),
|
||||
username=self.user.username,
|
||||
retry=Retry(max=get_config().RQ_RETRY_MAX, interval=get_config().RQ_RETRY_INTERVAL)
|
||||
retry=get_rq_retry()
|
||||
)
|
||||
|
@ -4,12 +4,12 @@ import hmac
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils import timezone
|
||||
from django_rq import get_queue
|
||||
from rq import Retry
|
||||
|
||||
from netbox.config import get_config
|
||||
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
|
||||
@ -118,5 +118,5 @@ def flush_webhooks(queue):
|
||||
timestamp=str(timezone.now()),
|
||||
username=data['username'],
|
||||
request_id=data['request_id'],
|
||||
retry=Retry(max=get_config().RQ_RETRY_MAX, interval=get_config().RQ_RETRY_INTERVAL)
|
||||
retry=get_rq_retry()
|
||||
)
|
||||
|
@ -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',
|
||||
)
|
||||
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user