From 8409c97e1ab07bddf64e5c0d0842b1cbae41eb67 Mon Sep 17 00:00:00 2001 From: "Chambers, Jason" Date: Thu, 13 Jun 2024 15:22:30 -0400 Subject: [PATCH] Default Logic if Queue does not exist --- docs/customization/custom-scripts.md | 6 +----- netbox/core/models/jobs.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/customization/custom-scripts.md b/docs/customization/custom-scripts.md index 1de97d331..cf4b3ce66 100644 --- a/docs/customization/custom-scripts.md +++ b/docs/customization/custom-scripts.md @@ -110,11 +110,7 @@ By default, a script can be scheduled for execution at a later time. Setting `sc ### `rq_queue_name` -This will override the standard `QUEUE_MAPPINGS` setting for the be process by the worker. If a worker is not set to monitor any custom mapping the job will never run. - -### `rq_queue_name` - -This will override the standard `QUEUE_MAPPINGS` setting for scripts the be process by the worker. If a worker is not set to monitor any custom mapping the job will never run. +This will override the standard `QUEUE_MAPPINGS` setting for the be process by the worker. If the queue is not found then the default logic found in the settings file will be used. ### `job_timeout` diff --git a/netbox/core/models/jobs.py b/netbox/core/models/jobs.py index 7960ba5c5..ec538edb1 100644 --- a/netbox/core/models/jobs.py +++ b/netbox/core/models/jobs.py @@ -213,12 +213,21 @@ class Job(models.Model): name: Name for the job (optional) user: The user responsible for running the job schedule_at: Schedule the job to be executed at the passed date and time + rq_queue_name: Queue name to route the job to for processing interval: Recurrence interval (in minutes) """ object_type = ObjectType.objects.get_for_model(instance, for_concrete_model=False) if rq_queue_name is None: rq_queue_name = get_queue_for_model(object_type.model) - queue = django_rq.get_queue(rq_queue_name) + queue = django_rq.get_queue(rq_queue_name) + else: + try: + queue = django_rq.get_queue(rq_queue_name) + except KeyError: + # User defined queue does not exist - return to default logic + rq_queue_name = get_queue_for_model(object_type.model) + queue = django_rq.get_queue(rq_queue_name) + status = JobStatusChoices.STATUS_SCHEDULED if schedule_at else JobStatusChoices.STATUS_PENDING job = Job.objects.create( object_type=object_type,