wait

package
v0.0.0-...-02c76fb Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 7 Imported by: 7

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" nonempty:"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.
	Timeout *time.Duration `hcl:"timeout"`

	// 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. If the interval is not
	// specified, it will default to 5 seconds.
	Interval *time.Duration `hcl:"interval"`

	// the amount of time to wait before running the first check and after a
	// successful check. If no grace period is specified, no grace period will be
	// taken into account.
	GracePeriod *time.Duration `hcl:"grace_period"`

	// 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(ctx context.Context, 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 *time.Duration, 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

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