瀏覽代碼

Introduce constants for RQ queue names

jeremystretch 3 年之前
父節點
當前提交
6ffd8aa320
共有 4 個文件被更改,包括 13 次插入5 次删除
  1. 2 1
      netbox/extras/models/models.py
  2. 2 1
      netbox/extras/webhooks.py
  3. 5 0
      netbox/netbox/constants.py
  4. 4 3
      netbox/netbox/settings.py

+ 2 - 1
netbox/extras/models/models.py

@@ -22,6 +22,7 @@ from extras.constants import *
 from extras.conditions import ConditionSet
 from extras.conditions import ConditionSet
 from extras.utils import FeatureQuery, image_upload
 from extras.utils import FeatureQuery, image_upload
 from netbox.config import get_config
 from netbox.config import get_config
+from netbox.constants import RQ_QUEUE_DEFAULT
 from netbox.models import ChangeLoggedModel
 from netbox.models import ChangeLoggedModel
 from netbox.models.features import (
 from netbox.models.features import (
     CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, JobResultsMixin, TagsMixin, WebhooksMixin,
     CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, JobResultsMixin, TagsMixin, WebhooksMixin,
@@ -682,7 +683,7 @@ class JobResult(models.Model):
             job_id=uuid.uuid4()
             job_id=uuid.uuid4()
         )
         )
 
 
-        rq_queue_name = get_config().QUEUE_MAPPINGS.get(obj_type.name, 'default')
+        rq_queue_name = get_config().QUEUE_MAPPINGS.get(obj_type.name, RQ_QUEUE_DEFAULT)
         queue = django_rq.get_queue(rq_queue_name)
         queue = django_rq.get_queue(rq_queue_name)
 
 
         if schedule_at:
         if schedule_at:

+ 2 - 1
netbox/extras/webhooks.py

@@ -6,6 +6,7 @@ from django.utils import timezone
 from django_rq import get_queue
 from django_rq import get_queue
 
 
 from netbox.config import get_config
 from netbox.config import get_config
+from netbox.constants import RQ_QUEUE_DEFAULT
 from netbox.registry import registry
 from netbox.registry import registry
 from utilities.api import get_serializer_for_model
 from utilities.api import get_serializer_for_model
 from utilities.utils import serialize_object
 from utilities.utils import serialize_object
@@ -79,7 +80,7 @@ def flush_webhooks(queue):
     """
     """
     Flush a list of object representation to RQ for webhook processing.
     Flush a list of object representation to RQ for webhook processing.
     """
     """
-    rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', 'default')
+    rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', RQ_QUEUE_DEFAULT)
     rq_queue = get_queue(rq_queue_name)
     rq_queue = get_queue(rq_queue_name)
     webhooks_cache = {
     webhooks_cache = {
         'type_create': {},
         'type_create': {},

+ 5 - 0
netbox/netbox/constants.py

@@ -1,2 +1,7 @@
 # Prefix for nested serializers
 # Prefix for nested serializers
 NESTED_SERIALIZER_PREFIX = 'Nested'
 NESTED_SERIALIZER_PREFIX = 'Nested'
+
+# RQ queue names
+RQ_QUEUE_DEFAULT = 'default'
+RQ_QUEUE_HIGH = 'high'
+RQ_QUEUE_LOW = 'low'

+ 4 - 3
netbox/netbox/settings.py

@@ -17,6 +17,7 @@ from extras.plugins import PluginConfig
 from sentry_sdk.integrations.django import DjangoIntegration
 from sentry_sdk.integrations.django import DjangoIntegration
 
 
 from netbox.config import PARAMS
 from netbox.config import PARAMS
+from netbox.constants import RQ_QUEUE_DEFAULT, RQ_QUEUE_HIGH, RQ_QUEUE_LOW
 
 
 
 
 #
 #
@@ -640,9 +641,9 @@ else:
     }
     }
 
 
 RQ_QUEUES = {
 RQ_QUEUES = {
-    'high': RQ_PARAMS,
-    'default': RQ_PARAMS,
-    'low': RQ_PARAMS,
+    RQ_QUEUE_HIGH: RQ_PARAMS,
+    RQ_QUEUE_DEFAULT: RQ_PARAMS,
+    RQ_QUEUE_LOW: RQ_PARAMS,
 }
 }
 
 
 # Add any queues defined in QUEUE_MAPPINGS
 # Add any queues defined in QUEUE_MAPPINGS