diff --git a/netbox/core/api/views.py b/netbox/core/api/views.py index 543812bda..5104bef77 100644 --- a/netbox/core/api/views.py +++ b/netbox/core/api/views.py @@ -202,7 +202,7 @@ class TaskDeleteView(APIView): return "Background Task" @extend_schema(responses={200: OpenApiTypes.OBJECT}) - def get(self, request, task_id, format=None): + def post(self, request, task_id, format=None): delete_rq_job(task_id) return HttpResponse(status=200) @@ -217,7 +217,7 @@ class TaskRequeueView(APIView): return "Background Task" @extend_schema(responses={200: OpenApiTypes.OBJECT}) - def get(self, request, task_id, format=None): + def post(self, request, task_id, format=None): requeue_rq_job(task_id) return HttpResponse(status=200) @@ -232,7 +232,7 @@ class TaskEnqueueView(APIView): return "Background Task" @extend_schema(responses={200: OpenApiTypes.OBJECT}) - def get(self, request, task_id, format=None): + def post(self, request, task_id, format=None): enqueue_rq_job(task_id) return HttpResponse(status=200) @@ -247,7 +247,7 @@ class TaskStopView(APIView): return "Background Task" @extend_schema(responses={200: OpenApiTypes.OBJECT}) - def get(self, request, task_id, format=None): + def post(self, request, task_id, format=None): stopped_jobs = stop_rq_job(task_id) if len(stopped_jobs) == 1: return HttpResponse(status=200) diff --git a/netbox/core/utils.py b/netbox/core/utils.py index 653287811..1f9b13ffb 100644 --- a/netbox/core/utils.py +++ b/netbox/core/utils.py @@ -16,6 +16,9 @@ from rq.registry import ( def get_rq_jobs_from_status(queue, status): + """ + Return the RQ jobs with the given status. + """ jobs = [] try: @@ -49,6 +52,9 @@ def get_rq_jobs_from_status(queue, status): def delete_rq_job(job_id): + """ + Deletes the specified RQ job. + """ config = QUEUES_LIST[0] try: job = RQ_Job.fetch(job_id, connection=get_redis_connection(config['connection_config']),) @@ -64,6 +70,9 @@ def delete_rq_job(job_id): def requeue_rq_job(job_id): + """ + Requeues the specified RQ job. + """ config = QUEUES_LIST[0] try: job = RQ_Job.fetch(job_id, connection=get_redis_connection(config['connection_config']),) @@ -77,6 +86,9 @@ def requeue_rq_job(job_id): def enqueue_rq_job(job_id): + """ + Enqueues the specified RQ job. + """ config = QUEUES_LIST[0] try: job = RQ_Job.fetch(job_id, connection=get_redis_connection(config['connection_config']),) @@ -106,6 +118,9 @@ def enqueue_rq_job(job_id): def stop_rq_job(job_id): + """ + Stops the specified RQ job. + """ config = QUEUES_LIST[0] try: job = RQ_Job.fetch(job_id, connection=get_redis_connection(config['connection_config']),) diff --git a/netbox/core/views.py b/netbox/core/views.py index 66b6f901d..0c6fa54c0 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -349,8 +349,7 @@ class BackgroundTaskListView(TableMixin, BaseRQView): if status == RQJobStatus.QUEUED: return queue.get_jobs() - jobs = get_rq_jobs_from_status(queue, status) - return jobs + return get_rq_jobs_from_status(queue, status) def get(self, request, queue_index, status): queue = get_queue_by_index(queue_index)