Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresReadyChecker is missing #68

Closed
aakavalevich opened this issue Jan 4, 2017 · 6 comments
Closed

PostgresReadyChecker is missing #68

aakavalevich opened this issue Jan 4, 2017 · 6 comments

Comments

@aakavalevich
Copy link

aakavalevich commented Jan 4, 2017

I use this library to start an instance of PosgreSQL database.
It would be nice to add a ReadyChecker for Postgres.

@aakavalevich
Copy link
Author

aakavalevich commented Jan 4, 2017

I have it like
`
class PostgresReadyChecker(container: DockerContainer) extends DockerReadyChecker {
val PostgresUser = "POSTGRES_USER="
val PostgresPassword = "POSTGRES_PASSWORD="
val PostgresDB = "POSTGRES_DB="
val maybePort = container.bindPorts.headOption.map(.1)
val maybeUser = container.env.find(
.startsWith(PostgresUser)).map(
.substring(PostgresUser.length))
val maybePassword = container.env.find(.startsWith(PostgresPassword)).map(.substring(PostgresPassword.length))
val maybeDB = container.env.find(.startsWith(PostgresDB)).map(.substring(PostgresDB.length))

override def apply(container: DockerContainerState)(implicit docker: DockerCommandExecutor, ec: ExecutionContext) =
container.getPorts().map(ports =>
Try {
Class.forName("org.postgresql.Driver")
val ip = DockerHelper.ip
val url = s"jdbc:postgresql://$ip:${maybePort.getOrElse(ports.values.head)}/"
Logger.info(s"Trying to obtain connection to $url with user $maybeUser, password = $maybePassword, and db = $maybeDB")
val maybeConnection =
for {
user <- maybeUser
password <- maybePassword
db <- maybeDB
} yield DriverManager.getConnection(url + db, user, password)
maybeConnection.map(_.close).isDefined
}.recover{
case e =>
Logger.info(e.getMessage)
false
}.getOrElse(false)
)
}
`

@aakavalevich
Copy link
Author

I can make a pull request if this functionality is needed.

@viktortnk
Copy link
Contributor

@aakavalevich
Copy link
Author

@viktortnk Thanks for your example, but is it included to the library? Can I reuse it without copying?

@viktortnk
Copy link
Contributor

@aakavalevich No, it is not included. Specific implementations are not shipped with library. I'd recommend to just copy it

@aakavalevich
Copy link
Author

Ok. I just thought, that Ready checker is similar to everyone and it would be nice to share it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants