def postgres_connection(connection_string, retry_counter=1):
try:
connection = psycopg2.connect(connection_string)
except psycopg2.OperationalError as e:
if retry_counter > LIMIT_RETRIES:
logging.error("CAN'T CONNECT TO POSTGRES")
logging.error("Check your connection settings.")
logging.error("Or increase (in docker-compose.yml):")
logging.error(
"TAIGA_DB_CHECK_SLEEP_INTERVAL / TAIGA_DB_CHECK_LIMIT_RETRIES."
)
logging.error("Exception messsage: {}".format(e))
sys.exit(1)
else:
logging.warning("Can't connect to Postgres. Will try again...")
time.sleep(SLEEP_INTERVAL)
retry_counter += 1
return postgres_connection(connection_string, retry_counter)
return connection
评论列表
文章目录