Преглед изворни кода

Closes #23658: Upgrade to rq 3.0 (#23812)

Co-authored-by: Zeyad <81588100+Corencas@users.noreply.github.com>
Zeyad Rabie пре 18 часа
родитељ
комит
d05e1acf40

+ 1 - 2
base_requirements.txt

@@ -146,9 +146,8 @@ redis
 requests
 
 # rq
-# Pinned below v3.0, whose new Worker.monitor_work_horse() signature breaks NetBox's tests
 # https://github.com/rq/rq/blob/master/CHANGES.md
-rq<3.0
+rq>=3.0
 
 # Django app for social-auth-core
 # https://github.com/python-social-auth/social-app-django/blob/master/CHANGELOG.md

+ 3 - 0
netbox/core/constants.py

@@ -16,6 +16,7 @@ class Badge:
 
 
 RQ_TASK_STATUSES = {
+    JobStatus.CREATED: Badge(_('Created'), 'dark'),
     JobStatus.QUEUED: Badge(_('Queued'), 'cyan'),
     JobStatus.FINISHED: Badge(_('Finished'), 'green'),
     JobStatus.FAILED: Badge(_('Failed'), 'red'),
@@ -24,6 +25,8 @@ RQ_TASK_STATUSES = {
     JobStatus.SCHEDULED: Badge(_('Scheduled'), 'purple'),
     JobStatus.STOPPED: Badge(_('Stopped'), 'orange'),
     JobStatus.CANCELED: Badge(_('Cancelled'), 'yellow'),
+    JobStatus.RATE_LIMITED: Badge(_('Rate limited'), 'pink'),
+    JobStatus.READY_TO_ENQUEUE: Badge(_('Ready to enqueue'), 'azure'),
 }
 
 JOB_LOG_ENTRY_LEVELS = {

+ 2 - 1
netbox/core/tests/test_api.py

@@ -565,6 +565,7 @@ class BackgroundTaskTestCase(RQQueueTestMixin, TestCase):
         # warning for this freshly-created (unregistered) worker; suppress the expected noise.
         with disable_logging():
             worker.prepare_job_execution(job)
+            execution = worker.prepare_execution(job)
         url = reverse('core-api:rqtask-stop', args=[job.id])
         self.assertEqual(job.get_status(), JobStatus.STARTED)
 
@@ -578,7 +579,7 @@ class BackgroundTaskTestCase(RQQueueTestMixin, TestCase):
         response = self.client.post(url, **self.header)
         self.assertEqual(response.status_code, 200)
         with disable_logging():
-            worker.monitor_work_horse(job, queue)  # Sets the job as Failed and removes from Started
+            worker.monitor_work_horse(job, queue, execution)  # Sets the job as Failed and removes from Started
         started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection)
         self.assertEqual(len(started_job_registry), 0)
 

+ 13 - 1
netbox/core/tests/test_tables.py

@@ -1,10 +1,12 @@
 import uuid
 from datetime import timedelta
 
-from django.test import TestCase
+from django.test import SimpleTestCase, TestCase
 from django.utils import timezone
+from rq.job import JobStatus
 
 from core.choices import JobStatusChoices
+from core.constants import RQ_TASK_STATUSES
 from core.models import Job, ObjectChange
 from core.tables import *
 from utilities.testing import TableTestCases
@@ -90,3 +92,13 @@ class ObjectChangeTableTestCase(TableTestCases.StandardTableTestCase):
 
 class ConfigRevisionTableTestCase(TableTestCases.StandardTableTestCase):
     table = ConfigRevisionTable
+
+
+class BackgroundTaskStatusBadgeTestCase(SimpleTestCase):
+    """
+    Every RQ job status needs a badge, or BackgroundTaskTable fails to render a task in that status.
+    """
+    def test_every_rq_status_has_a_badge(self):
+        for status in JobStatus:
+            with self.subTest(status=status):
+                self.assertIn(status, RQ_TASK_STATUSES)

+ 2 - 2
netbox/core/tests/test_views.py

@@ -771,7 +771,7 @@ class BackgroundTaskTestCase(RQQueueTestMixin, TestCase):
         # warning for this freshly-created (unregistered) worker; suppress the expected noise.
         with disable_logging():
             worker.prepare_job_execution(job)
-            worker.prepare_execution(job)
+            execution = worker.prepare_execution(job)
 
         self.assertEqual(job.get_status(), JobStatus.STARTED)
 
@@ -781,7 +781,7 @@ class BackgroundTaskTestCase(RQQueueTestMixin, TestCase):
         response = self.client.get(reverse('core:background_task_stop', args=[job.id]))
         self.assertEqual(response.status_code, 302)
         with disable_logging():
-            worker.monitor_work_horse(job, queue)  # Sets the job as Failed and removes from Started
+            worker.monitor_work_horse(job, queue, execution)  # Sets the job as Failed and removes from Started
         self.assertEqual(len(started_job_registry), 0)
 
         canceled_job_registry = FailedJobRegistry(queue.name, connection=queue.connection)

+ 1 - 1
requirements.txt

@@ -33,7 +33,7 @@ pymdown-extensions==12.1
 PyYAML==6.0.4
 redis==8.1.0
 requests==2.34.2
-rq==2.12.0
+rq==3.0.1
 social-auth-app-django==6.1.0
 social-auth-core==5.2.0
 sorl-thumbnail==13.5.0