Go to file
Marvin Preuss eb32ad48b3
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
ci: release for darwin
2021-09-01 13:55:52 +02:00
cmd adds progressbar to the commandline 2021-09-01 13:08:04 +02:00
vendor adds progressbar to the commandline 2021-09-01 13:08:04 +02:00
.drone.yml ci: upgrading golangci-lint and goreleaser 2021-09-01 13:07:13 +02:00
.gitignore meta: gitignore 2021-06-22 13:44:45 +02:00
.goreleaser.yml ci: release for darwin 2021-09-01 13:55:52 +02:00
don.go docs: readme 2021-09-01 13:43:50 +02:00
go.mod adds progressbar to the commandline 2021-09-01 13:08:04 +02:00
go.sum adds progressbar to the commandline 2021-09-01 13:08:04 +02:00
LICENSE adds LICENSE file 2021-06-21 09:54:30 +02:00
Makefile ci: adds homebrew 2021-06-22 12:33:41 +02:00
README.gif docs: readme 2021-09-01 13:43:50 +02:00
README.md docs: readme 2021-09-01 13:43:50 +02:00

don

GoDoc Go Report Card

Package don is a little helper if you need to check for the readiness of something. This could be a command to run (like ssh) or a db.Ping() for check of the readiness of a database container.

readme

Use as commandline tool

Download the tool from the download page or install via brew:

brew tap xsteadfastx/tap [https://github.com/xsteadfastx/homebrew-tap](https://github.com/xsteadfastx/homebrew-tap)
brew install don
don -t 15m -r 15s -c "ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@container"

This example checks every 15 seconds if the ssh container is ready. It would timeout with an error after 15 minutes.

Use as a library

If you want to use don as a library, it just takes a func() bool in don.Ready() have a function that runs the readiness check and returns true or false if its ready or not. The second argument is the overall timeout and the third argument is the check interval. Import it like this:

import go.xsfx.dev/don

Doing the readiness check like this:

if err := don.Ready(
	func() bool {
		db, err := sql.Open("oracle", dbConn)
		if err != nil {
			log.Warn().Err(err).Str("dbConn", dbConn).Msg("could not open connection")

			return false
		}

		if err := db.Ping(); err != nil {
			log.Warn().Err(err).Str("dbConn", dbConn).Msg("could not ping")

			return false
		}

		return true
	},
	10*time.Minute, // When to timeout completly.
	30*time.Second, // Whats the time between retries.
	false, // If you want a progressbar.
); err != nil {
	log.Error().Err(err).Msg("received error")
	teardown(pool, resource, tmpState.Name())
	os.Exit(1)
}

Functions

func Cmd

func Cmd(c string) func() bool

Cmd returns a func() bool for working with don.Ready(). It executes a command and returns a true if everything looks fine or a false if there was some kind of error.

func Ready

func Ready(f func() bool, timeout time.Duration, retry time.Duration, bar bool) error

Ready takes a function that executes something and returns a bool to indicate if something is ready or not. It returns an error if it timeouts.