Repository: pulp/pulpcore

Issue:
Update CI files for branch 3.23
[noissue]


Discussion:

Resolving patch:
diff --git a/pulpcore/app/models/task.py b/pulpcore/app/models/task.py
--- a/pulpcore/app/models/task.py
+++ b/pulpcore/app/models/task.py
@@ -143,7 +143,9 @@ def dirty_workers(self):
 
     def with_reservations(self, resources):
         """
-        Returns a worker with ANY of the reservations for resources specified by resource urls. This
+        Returns a worker with the resources reserved.
+
+        This worker may have ANY of the reservations for resources specified by resource urls. This
         is useful when looking for a worker to queue work against as we don't care if it doesn't
         have all the reservations as we can still try creating reservations for the additional
         resources we need.
@@ -160,6 +162,18 @@ def with_reservations(self, resources):
         """
         return self.filter(reservations__resource__in=resources).distinct().get()
 
+    def resource_managers(self):
+        """
+        Returns a queryset of resource managers.
+
+        Resource managers are identified by their name. Note that some of these may be offline.
+
+        Returns:
+            :class:`django.db.models.query.QuerySet`:  A query set of the Worker objects which
+                which match the resource manager name.
+        """
+        return self.filter(name__startswith=TASKING_CONSTANTS.RESOURCE_MANAGER_WORKER_NAME)
+
 
 class Worker(Model):
     """
diff --git a/pulpcore/tasking/tasks.py b/pulpcore/tasking/tasks.py
--- a/pulpcore/tasking/tasks.py
+++ b/pulpcore/tasking/tasks.py
@@ -83,13 +83,14 @@ def _queue_reserved_task(func, inner_task_id, resources, inner_args, inner_kwarg
                 time.sleep(0.25)
                 continue
             else:
-                task_status.state = TASK_STATES.RUNNING
-                task_status.save()
+                rq_worker = util.get_current_worker()
+                worker = Worker.objects.get(name=rq_worker.name)
+                task_status.worker = worker
+                task_status.set_running()
                 q = Queue('resource-manager', connection=redis_conn, is_async=False)
                 q.enqueue(func, args=inner_args, kwargs=inner_kwargs, job_id=inner_task_id,
                           job_timeout=TASK_TIMEOUT, **options)
-                task_status.state = TASK_STATES.COMPLETED
-                task_status.save()
+                task_status.set_completed()
                 return
 
         try:
diff --git a/pulpcore/tasking/util.py b/pulpcore/tasking/util.py
--- a/pulpcore/tasking/util.py
+++ b/pulpcore/tasking/util.py
@@ -4,7 +4,8 @@
 
 from django.db import transaction
 from django.urls import reverse
-from rq.job import Job
+from rq.job import Job, get_current_job
+from rq.worker import Worker
 
 from pulpcore.app.models import Task
 from pulpcore.app.util import get_view_name_for_model
@@ -92,3 +93,17 @@ def get_url(model):
         str: The path component of the resource url
     """
     return reverse(get_view_name_for_model(model, 'detail'), args=[model.pk])
+
+
+def get_current_worker():
+    """
+    Get the rq worker assigned to the current job
+
+    Returns:
+       class:`rq.worker.Worker`: The worker assigned to the current job
+    """
+    for worker in Worker.all():
+        if worker.get_current_job() == get_current_job():
+            return worker
+
+    return None


Test patch: