Skip to content

Commit

Permalink
monitor: ensure db connection before querying problems
Browse files Browse the repository at this point in the history
  • Loading branch information
hieplpvip committed Sep 26, 2024
1 parent dec9405 commit 6f1fc8f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions judge/bridge/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import time
from pathlib import Path

from django import db

from judge.models import Problem

try:
Expand All @@ -25,6 +27,10 @@
logger = logging.getLogger('judge.monitor')


def _ensure_connection():
db.connection.close_if_unusable_or_obsolete()


def find_glob_root(g: str) -> Path:
"""
Given a glob, find a directory that contains all its possible patterns
Expand Down Expand Up @@ -81,6 +87,7 @@ def update_supported_problems(self):
problems.append(problem)
problems = set(problems)

_ensure_connection()
problem_ids = list(Problem.objects.filter(code__in=list(problems)).values_list('id', flat=True))
self.judges.update_problems_all(problems, problem_ids)

Expand Down

0 comments on commit 6f1fc8f

Please sign in to comment.