Skip to content

Commit

Permalink
Avoid postgres timeout errors in watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Aug 21, 2023
1 parent 3d9bdfa commit e98f85d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 9 additions & 1 deletion reproserver/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ def connect(url=None, *, create=False):
host=os.environ['POSTGRES_HOST'],
database=os.environ['POSTGRES_DB'],
)
engine = create_engine(url, connect_args={'connect_timeout': 10})
engine = create_engine(
url,
connect_args={
'connect_timeout': 10,
'keepalives_idle': 30,
'keepalives_interval': 10,
'keepalives_count': 3,
},
)
else:
engine = create_engine(url)

Expand Down
22 changes: 11 additions & 11 deletions reproserver/run/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ async def _full_sync(self, api, DBSession):
raise

# Handle runs with missing pods
db = DBSession()
runs = (
db.query(database.Run)
.filter(database.Run.done == None) # noqa: E711
.all()
)
for run in runs:
if run.id not in self.running:
await self.connector.run_failed(run.id, "Pod deleted")
with DBSession() as db:
runs = (
db.query(database.Run)
.filter(database.Run.done == None) # noqa: E711
.all()
)
for run in runs:
if run.id not in self.running:
await self.connector.run_failed(run.id, "Pod deleted")

logger.info(
"Full sync complete, %d pods: %s",
Expand Down Expand Up @@ -425,8 +425,8 @@ async def _handle_watch_event(self, api, DBSession, event):
return

# Get run
db = DBSession()
run = db.query(database.Run).get(run_id)
with DBSession() as db:
run = db.query(database.Run).get(run_id)
if run is None:
logger.warning("Event in pod for unknown run %d", run_id)
return
Expand Down

0 comments on commit e98f85d

Please sign in to comment.