waitfores

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: MIT Imports: 6 Imported by: 0

README ¶

wait-for-es

GoDoc License Github All Releases GitHub release

Wait until Elasticsearch become available.


Why 🤔

When testing Elasticsearch in an automated way you have to wait for it to be up and ready to accept connections.

Install

go get github.com/blacktop/wait-for-es

Example

import (
    "context"
    "log"
    "time"

    w4e "github.com/blacktop/wait-for-es"
    "github.com/pkg/errors"
)

func main() {
    connCtx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
    defer cancel()

    w := w4e.WaitForEs{
        URL:     address,
        Timeout: timeout,
    }
    err := w.WaitForConnection(connCtx, timeout)
    if err != nil {
        log.Fatal(errors.Wrap(err, "failed to connect to elasticsearch"))
    }
}

CLI

Install

Download wait-for-es from releases

macOS

Via homebrew

$ brew install blacktop/tap/wait-for-es
Usage
$ wait-for-es --help

Wait until Elasticsearch become available

Usage:
  wait-for-es [flags]

Flags:
      --address string   elasticsearch address (default "http://localhost:9200")
      --config string    config file (default is $HOME/.wait-for-es.yaml)
  -H, --healthy          wait until cluster health is green
  -h, --help             help for wait-for-es
      --timeout int      timeout in seconds (default 60)
  -V, --verbose          verbose output
$ wait-for-es --address http://localhost:9200 --timeout 60 --healthy --verbose

INFO[0000] ===> trying to connect to elasticsearch
DEBU[0000] attempting to PING to: http://localhost:9200
DEBU[0000]  * could not connect to elasticsearch (sleeping for 1 second)
DEBU[0001] attempting to PING to: http://localhost:9200
DEBU[0001]  * could not connect to elasticsearch (sleeping for 1 second)
..SNIP...
DEBU[0021] cluster status is "green"
DEBU[0021] elasticSearch connection successful           cluster=elasticsearch code=200 url="http://localhost:9200" version=7.0.0
INFO[0021] elasticsearch came online after 21 seconds

License

MIT Copyright (c) 2019 blacktop

Documentation ¶

Overview ¶

Package waitfores is a Go package to wait for Elasticsearch.

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type WaitForEs ¶

type WaitForEs struct {
	URL      string
	Username string
	Password string
	Health   string
	Timeout  int64
}

WaitForEs contains the wait-for-es settings

func (*WaitForEs) WaitForConnection ¶

func (wfe *WaitForEs) WaitForConnection(ctx context.Context, timeout int64, healthy bool) error

WaitForConnection waits for connection to Elasticsearch to be ready

Directories ¶

Path Synopsis
cli

Jump to

Keyboard shortcuts

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