converge: github.com/asteris-llc/converge/resource/wait Index | Files | Directories

package wait

import "github.com/asteris-llc/converge/resource/wait"

Index

Package Files

preparer.go retrier.go wait.go

Constants

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
)

type Preparer Uses

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 Uses

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

Prepare creates a new wait type

type Retrier Uses

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 Uses

func PrepareRetrier(interval, gracePeriod *time.Duration, maxRetry *int) *Retrier

PrepareRetrier generates a Retrier from preparer input

func (*Retrier) RetryUntil Uses

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

RetryUntil implements a retry loop

type RetryFunc Uses

type RetryFunc func() (bool, error)

RetryFunc is the function to retry

type Wait Uses

type Wait struct {
    *shell.Shell
    *Retrier
}

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

func (*Wait) Apply Uses

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

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

func (*Wait) Messages Uses

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

Messages returns a summary of the attempts

Directories

PathSynopsis
port

Package wait imports 7 packages (graph) and is imported by 3 packages. Updated 2016-12-25. Refresh now. Tools for package owners.