[PR #16552] [CLOSED] Per-Script Worker Queue Setting #14862

Closed
opened 2025-12-29 23:27:09 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/16552
Author: @jchambers2012
Created: 6/13/2024
Status: Closed

Base: developHead: script_rq_queue_name


📝 Commits (10+)

  • 2455660 Update scripts.py with rq_queue_name
  • 259cb5a Update jobs.py add rq_queue_name
  • 99d2593 Update jobs.py
  • 1bc636d Update jobs.py Lint
  • c7970f0 Merge branch 'netbox-community:develop' into script_rq_queue_name
  • 3146a48 Add q_queue_name to docs
  • b203c9d Adding rq_queue_name to API and Views
  • 8409c97 Default Logic if Queue does not exist
  • a28810a wording
  • d8868ed wording

📊 Changes

5 files changed (+34 additions, -7 deletions)

View changed files

📝 docs/customization/custom-scripts.md (+4 -0)
📝 netbox/core/models/jobs.py (+23 -7)
📝 netbox/extras/api/views.py (+1 -0)
📝 netbox/extras/scripts.py (+5 -0)
📝 netbox/extras/views.py (+1 -0)

📄 Description

Fixes: #16516

This PR add a new Meta field to the scripts called rq_queue_name. This new field will allow time critical scripts to route to the high queue and run before scripts that are designed to be background jobs and run at a lower priority. If the script programmer tries to route the script to a non-existing queue, the current logic will route the script to the queue set to for scripts.

The PR was tested via the GUI and via the API. This was assessed by creating 4 Custom scripts that each route to diffrent queues. Three scripts were set to route to the standard high, default, low queues and a fourth was set to route to a queue called None that did not exist in configuration. The three scripts that had queue ran in the correct order with high script running first, followed by default then low. The fourth script that routed to None was redirected to the default queue.

GUI Tests:

image

image

API Tests:

image

Script Used for testing

from extras.scripts import *
import time


class testLowQue(Script):
    class Meta:
        name = "Log Test  - Que Low"
        scheduling_enabled = False
        description = ""
        rq_queue_name = "low"

    def run(self, data, commit):
        for i in range(6):
            self.log_info(f"Log Test - Sleeping for 10 Sec - Que Low: {i}")
            time.sleep(10)
        return str("")


class testDefaultQue(Script):
    class Meta:
        name = "Log Test  - Que Default"
        scheduling_enabled = False
        description = ""
        rq_queue_name = "default"

    def run(self, data, commit):
        for i in range(6):
            self.log_info(f"Log Test - Sleeping for 10 Sec - Que Default: {i}")
            time.sleep(10)
        return str("")


class testHighQue(Script):
    class Meta:
        name = "Log Test  - Que high"
        scheduling_enabled = False
        description = ""
        rq_queue_name = "high"

    def run(self, data, commit):
        for i in range(6):
            self.log_info(f"Log Test - Sleeping for 10 Sec - Que High: {i}")
            time.sleep(10)
        return str("")


class testNoneQue(Script):
    class Meta:
        name = "Log Test  - Que None"
        scheduling_enabled = False
        description = ""
        rq_queue_name = "None"

    def run(self, data, commit):
        for i in range(6):
            self.log_info(f"Log Test - Sleeping for 10 Sec - Que None: {i}")
            time.sleep(10)
        return str("")

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/16552 **Author:** [@jchambers2012](https://github.com/jchambers2012) **Created:** 6/13/2024 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `script_rq_queue_name` --- ### 📝 Commits (10+) - [`2455660`](https://github.com/netbox-community/netbox/commit/2455660865ba6077c29d0a62b29ed27356b1b9ba) Update scripts.py with rq_queue_name - [`259cb5a`](https://github.com/netbox-community/netbox/commit/259cb5acc03a1085bad7e2b470223db48bb2b188) Update jobs.py add rq_queue_name - [`99d2593`](https://github.com/netbox-community/netbox/commit/99d259341c3296fb47462fc8026af41023aaa439) Update jobs.py - [`1bc636d`](https://github.com/netbox-community/netbox/commit/1bc636d91b2b0606c05325d938eb2bc101ce1ce1) Update jobs.py Lint - [`c7970f0`](https://github.com/netbox-community/netbox/commit/c7970f0813cb20ec6ac28dfd425c817a264bf033) Merge branch 'netbox-community:develop' into script_rq_queue_name - [`3146a48`](https://github.com/netbox-community/netbox/commit/3146a4889af224d051cce80e7d2feabc7a6feed7) Add q_queue_name to docs - [`b203c9d`](https://github.com/netbox-community/netbox/commit/b203c9d916c152fcb2fef7acd9a092d934390348) Adding rq_queue_name to API and Views - [`8409c97`](https://github.com/netbox-community/netbox/commit/8409c97e1ab07bddf64e5c0d0842b1cbae41eb67) Default Logic if Queue does not exist - [`a28810a`](https://github.com/netbox-community/netbox/commit/a28810a98c2d04f08bd3e47403cd39753f88a4a8) wording - [`d8868ed`](https://github.com/netbox-community/netbox/commit/d8868ed15353fab4c818765abbdc7260bb9ec48c) wording ### 📊 Changes **5 files changed** (+34 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/customization/custom-scripts.md` (+4 -0) 📝 `netbox/core/models/jobs.py` (+23 -7) 📝 `netbox/extras/api/views.py` (+1 -0) 📝 `netbox/extras/scripts.py` (+5 -0) 📝 `netbox/extras/views.py` (+1 -0) </details> ### 📄 Description ### Fixes: #16516 This PR add a new Meta field to the scripts called `rq_queue_name`. This new field will allow time critical scripts to route to the `high` queue and run before scripts that are designed to be background jobs and run at a lower priority. If the script programmer tries to route the script to a non-existing queue, the current logic will route the script to the queue set to for scripts. The PR was tested via the GUI and via the API. This was assessed by creating 4 Custom scripts that each route to diffrent queues. Three scripts were set to route to the standard `high`, `default`, `low` queues and a fourth was set to route to a queue called `None` that did not exist in configuration. The three scripts that had queue ran in the correct order with high script running first, followed by default then low. The fourth script that routed to `None` was redirected to the default queue. ### GUI Tests: ![image](https://github.com/netbox-community/netbox/assets/6090690/764e5610-6be4-4bf7-96b4-cf4d1e7b0bce) ![image](https://github.com/netbox-community/netbox/assets/6090690/09ee0c8a-2d6b-4b64-a594-c15b1214ccc4) ### API Tests: ![image](https://github.com/netbox-community/netbox/assets/6090690/16881196-2adf-4e5b-aafa-226b0486fe38) ### Script Used for testing ```python from extras.scripts import * import time class testLowQue(Script): class Meta: name = "Log Test - Que Low" scheduling_enabled = False description = "" rq_queue_name = "low" def run(self, data, commit): for i in range(6): self.log_info(f"Log Test - Sleeping for 10 Sec - Que Low: {i}") time.sleep(10) return str("") class testDefaultQue(Script): class Meta: name = "Log Test - Que Default" scheduling_enabled = False description = "" rq_queue_name = "default" def run(self, data, commit): for i in range(6): self.log_info(f"Log Test - Sleeping for 10 Sec - Que Default: {i}") time.sleep(10) return str("") class testHighQue(Script): class Meta: name = "Log Test - Que high" scheduling_enabled = False description = "" rq_queue_name = "high" def run(self, data, commit): for i in range(6): self.log_info(f"Log Test - Sleeping for 10 Sec - Que High: {i}") time.sleep(10) return str("") class testNoneQue(Script): class Meta: name = "Log Test - Que None" scheduling_enabled = False description = "" rq_queue_name = "None" def run(self, data, commit): for i in range(6): self.log_info(f"Log Test - Sleeping for 10 Sec - Que None: {i}") time.sleep(10) return str("") ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:27:09 +01:00
adam closed this issue 2025-12-29 23:27:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14862