feature/Add property database_query_timeout_in_seconds

This commit is contained in:
Marko Milić 2023-08-04 12:15:08 +02:00
parent 3494ca5d2f
commit 07350c8fbd
2 changed files with 23 additions and 1 deletions

View File

@ -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_

View File

@ -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 =>