wait

package
v0.0.0-...-215933a Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInterval is the default amount of time to wait in between checks
	DefaultInterval = 5 * time.Second

	// DefaultGracePeriod is the amount of time to wait before running the first
	// check and after a successful check
	DefaultGracePeriod = time.Duration(0)

	// DefaultRetries is the default number of times to retry before failing
	DefaultRetries = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Preparer

type Preparer struct {
	// the shell interpreter that will be used for your scripts. `/bin/sh` is
	// used by default.
	Interpreter string `hcl:"interpreter"`

	// the script to run to check if a resource is ready. exit with exit code 0 if
	// the resource is healthy, and 1 (or above) otherwise.
	Check string `hcl:"check" required:"true"`

	// flags to pass to the `interpreter` binary to check validity. For
	// `/bin/sh` this is `-n`.
	CheckFlags []string `hcl:"check_flags"`

	// flags to pass to the interpreter at execution time.
	ExecFlags []string `hcl:"exec_flags"`

	// the amount of time the command will wait before halting forcefully. The
	// format is Go's duration string. A duration string is a possibly signed
	// sequence of decimal numbers, each with optional fraction and a unit
	// suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns",
	// "us" (or "µs"), "ms", "s", "m", "h".
	Timeout string `hcl:"timeout" doc_type:"duration string"`

	// the working directory this command should be run in.
	Dir string `hcl:"dir"`

	// any environment variables that should be passed to the command.
	Env map[string]string `hcl:"env"`

	// the amount of time to wait in between checks. The format is Go's duration
	// string. A duration string is a possibly signed sequence of decimal numbers,
	// each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or
	// "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". If
	// the interval is not specified, it will default to 5 seconds.
	Interval string `hcl:"interval" doc_type:"duration string"`

	// the amount of time to wait before running the first check and after a
	// successful check. The format is Go's duration string. A duration string is
	// a possibly signed sequence of decimal numbers, each with optional fraction
	// and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units
	// are "ns", "us" (or "µs"), "ms", "s", "m", "h". If no grace period is
	// specified, no grace period will be taken into account.
	GracePeriod string `hcl:"grace_period" doc_type:"duration string"`

	// the maximum number of attempts before the wait fails. If the maximum number
	// of retries is not set, it will default to 5.
	MaxRetry int `hcl:"max_retry"`
}

Preparer handles wait.query tasks

func (*Preparer) Prepare

func (p *Preparer) Prepare(render resource.Renderer) (resource.Task, error)

Prepare creates a new wait type

type Retrier

type Retrier struct {
	GracePeriod time.Duration
	Interval    time.Duration
	MaxRetry    int
	RetryCount  int
	Duration    time.Duration
}

Retrier can be included in resources to provide retry capabilities

func PrepareRetrier

func PrepareRetrier(interval, gracePeriod string, maxRetry int) *Retrier

PrepareRetrier generates a Retrier from preparer input

func (*Retrier) RetryUntil

func (r *Retrier) RetryUntil(retryFunc RetryFunc) (bool, error)

RetryUntil implements a retry loop

type RetryFunc

type RetryFunc func() (bool, error)

RetryFunc is the function to retry

type Wait

type Wait struct {
	*shell.Shell
	*Retrier
}

Wait waits for a shell task to return 0 or reaches max failure threshold

func (*Wait) Apply

func (w *Wait) Apply() (resource.TaskStatus, error)

Apply retries the check until it passes or returns max failure threshold

func (*Wait) Messages

func (w *Wait) Messages() []string

Messages returns a summary of the attempts

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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