From a0fceefb68bf62a1dc558a8e27de8d3a4312539c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 26 Nov 2024 09:27:04 -0500 Subject: [PATCH] Misc cleanup --- netbox/core/api/schema.py | 8 +++----- netbox/core/utils.py | 40 +++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/netbox/core/api/schema.py b/netbox/core/api/schema.py index a8feffc60..663ee2899 100644 --- a/netbox/core/api/schema.py +++ b/netbox/core/api/schema.py @@ -158,11 +158,9 @@ class NetBoxAutoSchema(AutoSchema): fields = {} if hasattr(serializer, 'child') else serializer.fields remove_fields = [] - """ - If you get a failure here for: AttributeError: 'cached_property' object has no attribute 'items' - it is probably because you are using a viewsets.ViewSet for the API View and are defining a - serializer_class. You will also need to define a get_serializer function like GenericAPIView. - """ + # If you get a failure here for "AttributeError: 'cached_property' object has no attribute 'items'" + # it is probably because you are using a viewsets.ViewSet for the API View and are defining a + # serializer_class. You will also need to define a get_serializer() method like for GenericAPIView. for child_name, child in fields.items(): # read_only fields don't need to be in writable (write only) serializers if 'read_only' in dir(child) and child.read_only: diff --git a/netbox/core/utils.py b/netbox/core/utils.py index e980a2658..26adfdfa2 100644 --- a/netbox/core/utils.py +++ b/netbox/core/utils.py @@ -14,6 +14,28 @@ from rq.registry import ( StartedJobRegistry, ) +__all__ = ( + 'delete_rq_job', + 'enqueue_rq_job', + 'get_rq_jobs', + 'get_rq_jobs_from_status', + 'requeue_rq_job', + 'stop_rq_job', +) + + +def get_rq_jobs(): + """ + Return a list of all RQ jobs. + """ + jobs = set() + + for queue in QUEUES_LIST: + queue = get_queue(queue['name']) + jobs.update(queue.get_jobs()) + + return list(jobs) + def get_rq_jobs_from_status(queue, status): """ @@ -51,19 +73,9 @@ def get_rq_jobs_from_status(queue, status): return jobs -def get_rq_jobs(): - jobs = set() - - for queue in QUEUES_LIST: - queue = get_queue(queue['name']) - jobs.update(queue.get_jobs()) - - return list(jobs) - - def delete_rq_job(job_id): """ - Deletes the specified RQ job. + Delete the specified RQ job. """ config = QUEUES_LIST[0] try: @@ -81,7 +93,7 @@ def delete_rq_job(job_id): def requeue_rq_job(job_id): """ - Requeues the specified RQ job. + Requeue the specified RQ job. """ config = QUEUES_LIST[0] try: @@ -97,7 +109,7 @@ def requeue_rq_job(job_id): def enqueue_rq_job(job_id): """ - Enqueues the specified RQ job. + Enqueue the specified RQ job. """ config = QUEUES_LIST[0] try: @@ -129,7 +141,7 @@ def enqueue_rq_job(job_id): def stop_rq_job(job_id): """ - Stops the specified RQ job. + Stop the specified RQ job. """ config = QUEUES_LIST[0] try: