Skip to content

Commit

Permalink
Merge pull request #314 from ulitol97/master
Browse files Browse the repository at this point in the history
Customizable stream timeout in Docker.
  • Loading branch information
ulitol97 authored May 13, 2022
2 parents 169b426 + c34941c commit c08856b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ object Server {
*/
val defaultVerbosity = 0

/** Environment variable checked by the app to know how long to keep waiting for
* items coming via stream
*/
val envVarStreamTimeout = "STREAM_TIMEOUT"

/** System property checked by the app to know how long to keep waiting for
* items coming via stream
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.effect.IO
import com.typesafe.scalalogging.LazyLogging
import es.weso.rdfshape.server.Server.{
defaultStreamTimeout,
envVarStreamTimeout,
systemPropertyStreamTimeout
}
import es.weso.rdfshape.server.api.routes.schema.logic.operations.stream.configuration.{
Expand Down Expand Up @@ -56,10 +57,19 @@ private[schema] object CometTransformations extends LazyLogging {
* Retrieved from a system property which can be overridden by CLI args.
*/
private lazy val timeout = {
val timeoutFromSystemProp =
Integer
.getInteger(systemPropertyStreamTimeout, defaultStreamTimeout)
.toLong
val timeoutFromSystemProp = {
// Try to fetch in env vars
Option(System.getenv(envVarStreamTimeout))
.flatMap(_.toIntOption)
.map(_.toLong)
// Else fetch from system properties, resorting to the default value
// if none is found/parseable
.getOrElse(
Integer
.getInteger(systemPropertyStreamTimeout, defaultStreamTimeout)
.toLong
)
}

FiniteDuration(timeoutFromSystemProp, SECONDS)
}
Expand Down

0 comments on commit c08856b

Please sign in to comment.