我已经使用SQLAlchemy开发了一个flask应用程序,该应用程序连接到snowflake DB作为后端。如果网站闲置超过4小时,我就遇到了snowflake身份验证令牌过期的问题。我在Google中查看了一个答案
https://github.com/snowflakedb/gosnowflake/issues/160
我使用APScheduler实现了心跳代码,该代码每50分钟触发一次“ Select 1”,但是如果会话在浏览器(SSO)中处于活动状态,则会引发“身份验证令牌已过期”错误。
from sqlalchemy import create_engine
engine = create_engine('snowflake://<connection-string>' )
connection = engine.connect()
names = connection.execute_query("select names from employees")
def sensor():
""" Function for scheduling purposes. """
v = cursor.execute("""select 1""")
v = v.fetchall()
print(v)
sched = BackgroundScheduler(daemon=True)
sched.add_job(sensor,'interval',minutes=50)
sched.start()