From f8339f9d41c504beb85f1d8ab6721c95f30101fc Mon Sep 17 00:00:00 2001 From: HK-Mattew Date: Mon, 29 Jul 2024 15:31:12 -0300 Subject: [PATCH 1/3] Fixed acquire_jobs method in MongoDB DataStore. --- .gitignore | 1 + src/apscheduler/datastores/mongodb.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cc770a8f..7583132c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ docs/_build/ build/ virtualenv/ venv*/ +env*/ example.sqlite diff --git a/src/apscheduler/datastores/mongodb.py b/src/apscheduler/datastores/mongodb.py index 44e2b901..19681196 100644 --- a/src/apscheduler/datastores/mongodb.py +++ b/src/apscheduler/datastores/mongodb.py @@ -628,7 +628,7 @@ async def acquire_jobs( ) async for doc in cursor: task_max_running_jobs = doc["max_running_jobs"] - task_job_slots_left[doc["_id"]] = doc["max_running_jobs"] + task_job_slots_left[doc["_id"]] = (doc["max_running_jobs"] - doc["running_jobs"]) acquired_jobs: list[Job] = [] skipped_job_ids: list[UUID] = [] @@ -684,10 +684,13 @@ async def acquire_jobs( continue # Skip and un-acquire the job if no more slots are available - if not task_job_slots_left.get(job.task_id, float("inf")): + task_slots_left = task_job_slots_left.get(job.task_id, float("inf")) + if not task_slots_left or running_job_count_increments[job.task_id] == task_slots_left: self._logger.debug( "Skipping job %s because task %r has the maximum " "number of %d jobs already running", + job, + job.task_id, task_max_running_jobs, ) skipped_job_ids.append(job.id) From 66659d3bafcac4022ce9835297aa44e6ab400b48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:36:05 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/apscheduler/datastores/mongodb.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apscheduler/datastores/mongodb.py b/src/apscheduler/datastores/mongodb.py index 19681196..01baa56e 100644 --- a/src/apscheduler/datastores/mongodb.py +++ b/src/apscheduler/datastores/mongodb.py @@ -628,7 +628,9 @@ async def acquire_jobs( ) async for doc in cursor: task_max_running_jobs = doc["max_running_jobs"] - task_job_slots_left[doc["_id"]] = (doc["max_running_jobs"] - doc["running_jobs"]) + task_job_slots_left[doc["_id"]] = ( + doc["max_running_jobs"] - doc["running_jobs"] + ) acquired_jobs: list[Job] = [] skipped_job_ids: list[UUID] = [] @@ -685,7 +687,10 @@ async def acquire_jobs( # Skip and un-acquire the job if no more slots are available task_slots_left = task_job_slots_left.get(job.task_id, float("inf")) - if not task_slots_left or running_job_count_increments[job.task_id] == task_slots_left: + if ( + not task_slots_left + or running_job_count_increments[job.task_id] == task_slots_left + ): self._logger.debug( "Skipping job %s because task %r has the maximum " "number of %d jobs already running", From 975e148733dcc829b710a90532335c9d177a6a66 Mon Sep 17 00:00:00 2001 From: "Mattew S." <52506836+HK-Mattew@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:53:04 -0300 Subject: [PATCH 3/3] correcting condition. --- src/apscheduler/datastores/mongodb.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/apscheduler/datastores/mongodb.py b/src/apscheduler/datastores/mongodb.py index 01baa56e..2aea594c 100644 --- a/src/apscheduler/datastores/mongodb.py +++ b/src/apscheduler/datastores/mongodb.py @@ -686,11 +686,7 @@ async def acquire_jobs( continue # Skip and un-acquire the job if no more slots are available - task_slots_left = task_job_slots_left.get(job.task_id, float("inf")) - if ( - not task_slots_left - or running_job_count_increments[job.task_id] == task_slots_left - ): + if not task_job_slots_left.get(job.task_id, float("inf")): self._logger.debug( "Skipping job %s because task %r has the maximum " "number of %d jobs already running",