Skip to content

Commit

Permalink
Now it shuts down process if it cannot create Redis secondary index
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnestacado committed Sep 21, 2022
1 parent d62ec79 commit 48cb605
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/main/scala/com/ing/wbaa/rokku/sts/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ object Server extends App {

override protected[this] def redisSettings: RedisSettings = RedisSettings(system)

//Connects to Redis on startup and initializes indeces
initializeUserSearchIndex(redisPooledConnection)

registerTerminationCallback(() => {
logger.info("Closing redis connection pool...")
redisPooledConnection.close()
})

//Connects to Redis on startup and initializes indeces
try {
initializeUserSearchIndex(redisPooledConnection)
} catch {
case ex: RedisSecondaryIndexException =>
logger.error(s"Unable to create index $UsersIndex. Error: ${ex.getMessage()}. Exiting...")
sys.exit(1)
}

}.startup
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ trait RedisModel extends Encryption {

private val DuplicateIndexExceptionMsg = "Index already exists"

case class RedisSecondaryIndexException(message: String) extends Exception

object UserKey {
def encode(username: Username): String = {
s"$UserKeyPrefix${username.value}"
Expand Down Expand Up @@ -89,7 +91,7 @@ trait RedisModel extends Encryption {
case DuplicateIndexExceptionMsg =>
logger.info(s"Index ${UsersIndex} already exists. Continuing...")
case _ =>
logger.error(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}")
throw new RedisSecondaryIndexException(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}")
}
case exc: Exception =>
logger.error(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}")
Expand Down

0 comments on commit 48cb605

Please sign in to comment.