waitfor

package
v0.0.0-...-6e8e918 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func() error

Check is function that determines if a dependency is available it returns an error if the dependency is not ready.

func DatabaseReady

func DatabaseReady(driver, datasource string) Check

DatabaseReady determines if a database can be connected to. It takes a driver such as mysql or postgres-db and a datasource string. e.g. to connect to a postgres database call the method with these parameters DatabaseReady("postgres", "host=localhost port=5432 user=postgres password=secret dbname=postgres sslmode=disable")

func ServiceListening

func ServiceListening(addr string, timeout time.Duration) Check

ServiceListening verifies if the endpoint specified by addr is listening. The address string may contain a port e.g. 192.168.0.1:1234

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a dependency Handler. It maintains a list of dependencies to check

func NewDependencies

func NewDependencies() *Handler

NewDependencies returns a dependancy handler. This can be used to add multiple dependencies for an application. Calling wait on the handler will cause the handler to wait until all dependencies are ready, or until it timesout.

Example
package main

import (
	"log"
	"time"

	"github.com/davejohnston/waitfor/pkg/waitfor"
)

func main() {
	dependencies := waitfor.NewDependencies()
	dependencies.Add("rest-api", waitfor.ServiceListening("0.0.0.0:9999", 10*time.Second))
	err := dependencies.Wait()
	if err != nil {
		log.Fatal(err)
	}
}

func (*Handler) Add

func (h *Handler) Add(name string, waitFor Check)

Add a new dependency check e.g dependancies = waitfor.NewDependencies() dependancies.Add("rest-endpoint", waitfor.ServiceListening("0.0.0.0:8443", 10*time.Second))

func (*Handler) Wait

func (h *Handler) Wait(options ...Options) error

Wait executes the check for all dependencies If any dependency fails after the given number of retries and timeouts it will return error. All dependencies are checked in parallel.

type Options

type Options struct {
	Retries int
	Timeout time.Duration
}

Options defines the retry and timeout parameters when performing checks

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL