Refactor Query.get() => Session.get() per SQLAlchemy 1.4

This commit is contained in:
Lance Edgar 2023-02-11 22:24:56 -06:00
parent f7f60eff85
commit 995e0dde0a

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,15 +24,12 @@
TempMon client daemon TempMon client daemon
""" """
from __future__ import unicode_literals, absolute_import
import time import time
import datetime import datetime
import random import random
import socket import socket
import logging import logging
import six
from sqlalchemy.exc import OperationalError from sqlalchemy.exc import OperationalError
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
@ -86,7 +83,7 @@ class TempmonClient(Daemon):
session = Session() session = Session()
try: try:
client = session.query(tempmon.Client).get(client_uuid) client = session.get(tempmon.Client, client_uuid)
self.delay = client.delay or 60 self.delay = client.delay or 60
if client.enabled: if client.enabled:
for probe in client.enabled_probes(): for probe in client.enabled_probes():
@ -111,7 +108,7 @@ class TempmonClient(Daemon):
# first time after DB stop. but in the case of DB stop, # first time after DB stop. but in the case of DB stop,
# subsequent errors will instead match the second test # subsequent errors will instead match the second test
if error.connection_invalidated or ( if error.connection_invalidated or (
'could not connect to server: Connection refused' in six.text_type(error)): 'could not connect to server: Connection refused' in str(error)):
# only suppress logging for 3 failures, after that we let them go # only suppress logging for 3 failures, after that we let them go
# TODO: should make the max attempts configurable # TODO: should make the max attempts configurable
@ -119,7 +116,7 @@ class TempmonClient(Daemon):
log_error = False log_error = False
log.debug("database connection failure #%s: %s", log.debug("database connection failure #%s: %s",
self.failed_checks, self.failed_checks,
six.text_type(error)) str(error))
# send error email unless we're suppressing it for now # send error email unless we're suppressing it for now
if log_error: if log_error: