Skip to content

Commit

Permalink
Merge pull request #17319 from mvdbeek/scope_out_monitor_loop
Browse files Browse the repository at this point in the history
[23.2] Scope session for job  runner monitor loop
  • Loading branch information
jdavcs authored Jan 17, 2024
2 parents b9ba44b + e55a099 commit 064360d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/galaxy/jobs/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
import traceback
import typing
import uuid
from queue import (
Empty,
Queue,
Expand All @@ -33,10 +34,7 @@
job_script,
write_script,
)
from galaxy.model.base import (
check_database_connection,
transaction,
)
from galaxy.model.base import transaction
from galaxy.tool_util.deps.dependencies import (
JobInfo,
ToolInfo,
Expand Down Expand Up @@ -830,12 +828,18 @@ def monitor(self):
self.watched.append(async_job_state)
except Empty:
pass
# Ideally we'd construct a sqlalchemy session now and pass it into `check_watched_items`
# and have that be the only session being used. The next best thing is to scope
# the session and discard it after each check_watched_item loop
scoped_id = str(uuid.uuid4())
self.app.model.set_request_id(scoped_id)
# Iterate over the list of watched jobs and check state
try:
check_database_connection(self.sa_session)
self.check_watched_items()
except Exception:
log.exception("Unhandled exception checking active jobs")
finally:
self.app.model.unset_request_id(scoped_id)
# Sleep a bit before the next state check
time.sleep(self.app.config.job_runner_monitor_sleep)

Expand Down

0 comments on commit 064360d

Please sign in to comment.