From 07350c8fbd7a83093a2c3046e413400173d81b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 4 Aug 2023 12:15:08 +0200 Subject: [PATCH] feature/Add property database_query_timeout_in_seconds --- .../resources/props/sample.props.template | 3 +++ .../main/scala/bootstrap/liftweb/Boot.scala | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/obp-api/src/main/resources/props/sample.props.template b/obp-api/src/main/resources/props/sample.props.template index 37e90c377..6f496101c 100644 --- a/obp-api/src/main/resources/props/sample.props.template +++ b/obp-api/src/main/resources/props/sample.props.template @@ -100,6 +100,9 @@ read_authentication_type_validation_requires_role=false ## enable logging all the database queries in log file #logging.database.queries.enable=true +## enable logging all the database queries in log file +#database_query_timeout_in_seconds= + ##Added Props property_name_prefix, default is OBP_. This adds the prefix only for the system environment property name, eg: db.driver --> OBP_db.driver #system_environment_property_name_prefix=OBP_ diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index d92a482ec..b10785f09 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -149,7 +149,7 @@ import net.liftweb.util.Helpers._ import net.liftweb.util.{DefaultConnectionIdentifier, Helpers, Props, Schedule, _} import org.apache.commons.io.FileUtils -import scala.concurrent.ExecutionContext +import scala.concurrent.{ExecutionContext, Future} /** * A class that's instantiated early and run. It allows the application @@ -279,6 +279,25 @@ class Boot extends MdcLoggable { } } } + + // Database query timeout + APIUtil.getPropsValue("database_query_timeout_in_seconds").map { timeoutInSeconds => + tryo(timeoutInSeconds.toInt).isDefined match { + case true => + DB.queryTimeout = Full(timeoutInSeconds.toInt) + logger.info(s"Query timeout database_query_timeout_in_seconds is set to ${timeoutInSeconds} seconds") + case false => + logger.error( + s""" + |------------------------------------------------------------------------------------ + |Query timeout database_query_timeout_in_seconds [${timeoutInSeconds}] is not an integer value. + |Actual DB.queryTimeout value: ${DB.queryTimeout} + |------------------------------------------------------------------------------------""".stripMargin) + } + + } + + implicit val formats = CustomJsonFormats.formats LiftRules.statelessDispatch.prepend { case _ if tryo(DB.use(DefaultConnectionIdentifier){ conn => conn}.isClosed).isEmpty =>