Skip to content

Commit

Permalink
Fixed acquire_jobs method in MongoDB DataStore.
Browse files Browse the repository at this point in the history
  • Loading branch information
HK-Mattew committed Jul 29, 2024
1 parent 783129c commit f8339f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ docs/_build/
build/
virtualenv/
venv*/
env*/
example.sqlite
7 changes: 5 additions & 2 deletions src/apscheduler/datastores/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f8339f9

Please sign in to comment.