From 511971691166b6ba9be476cd872416901ad480c3 Mon Sep 17 00:00:00 2001 From: eswolinsky3241 <58117461+eswolinsky3241@users.noreply.github.com> Date: Fri, 25 Nov 2022 22:37:27 -0500 Subject: [PATCH] Persist worker_name after job is finished (#1730) * Persist worker_name after job is finished Persisting the worker_name on the job object in Redis would allow for debugging and analyzing logs from the worker * Remove redundent job.save() method call * Remove check for null worker Now that worker name is persisted after job finishes or fails, no need to assert that worker name is None * Change github runner to Ubuntu 20.04 * Change github runner to Ubuntu 20.04 --- .github/workflows/codeql.yaml | 2 +- .github/workflows/dependencies.yml | 2 +- .github/workflows/docker.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/workflow.yml | 2 +- rq/worker.py | 4 ---- tests/test_worker.py | 1 - 7 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index 4e33500e..07b94a06 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -7,7 +7,7 @@ on: jobs: CodeQL-Build: # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 permissions: # required for all workflows diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index 57209169..42b0389e 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -10,7 +10,7 @@ jobs: build: if: github.repository == 'rq/rq' name: Python${{ matrix.python-version }}/Redis${{ matrix.redis-version }}/redis-py${{ matrix.redis-py-version }} - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: ["3.6", "3.7", "3.8.3", "3.9", "3.10"] diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b9123a1b..7a9dda60 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,7 +14,7 @@ permissions: jobs: push: if: github.repository == 'rq/rq' - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d236d606..b8721e30 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ permissions: jobs: lint: name: Lint - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7d03da19..7b0a28d9 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -12,7 +12,7 @@ permissions: jobs: build: name: Python${{ matrix.python-version }}/Redis${{ matrix.redis-version }}/redis-py${{ matrix.redis-py-version }} - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: ["3.6", "3.7", "3.8.3", "3.9", "3.10"] diff --git a/rq/worker.py b/rq/worker.py index dff9be03..e44aa9fc 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -980,7 +980,6 @@ class Worker: job_class=self.job_class, serializer=self.serializer ) - job.worker_name = None # check whether a job was stopped intentionally and set the job # status appropriately if it was this job. @@ -1060,8 +1059,6 @@ class Worker: if result_ttl != 0: self.log.debug('Setting job %s status to finished', job.id) job.set_status(JobStatus.FINISHED, pipeline=pipeline) - job.worker_name = None - # Result should be saved in job hash only if server # doesn't support Redis streams include_result = not self.supports_redis_streams @@ -1071,7 +1068,6 @@ class Worker: if self.supports_redis_streams: Result.create(job, Result.Type.SUCCESSFUL, return_value=job._result, ttl=result_ttl, pipeline=pipeline) - finished_job_registry = queue.finished_job_registry finished_job_registry.add(job, result_ttl, pipeline) diff --git a/tests/test_worker.py b/tests/test_worker.py index 5d4ad341..6c7b4055 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -379,7 +379,6 @@ class TestWorker(RQTestCase): # Check the job job = Job.fetch(job.id) self.assertEqual(job.origin, q.name) - self.assertIsNone(job.worker_name) # Worker name is cleared after failures # Should be the original enqueued_at date, not the date of enqueueing # to the failed queue