github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/client/driver/structs/structs.go (about)

     1  package structs
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	cgroupConfig "github.com/opencontainers/runc/libcontainer/configs"
     8  )
     9  
    10  const (
    11  	// The default user that the executor uses to run tasks
    12  	DefaultUnpriviledgedUser = "nobody"
    13  
    14  	// CheckBufSize is the size of the check output result
    15  	CheckBufSize = 4 * 1024
    16  )
    17  
    18  // WaitResult stores the result of a Wait operation.
    19  type WaitResult struct {
    20  	ExitCode int
    21  	Signal   int
    22  	Err      error
    23  }
    24  
    25  func NewWaitResult(code, signal int, err error) *WaitResult {
    26  	return &WaitResult{
    27  		ExitCode: code,
    28  		Signal:   signal,
    29  		Err:      err,
    30  	}
    31  }
    32  
    33  func (r *WaitResult) Successful() bool {
    34  	return r.ExitCode == 0 && r.Signal == 0 && r.Err == nil
    35  }
    36  
    37  func (r *WaitResult) String() string {
    38  	return fmt.Sprintf("Wait returned exit code %v, signal %v, and error %v",
    39  		r.ExitCode, r.Signal, r.Err)
    40  }
    41  
    42  // IsolationConfig has information about the isolation mechanism the executor
    43  // uses to put resource constraints and isolation on the user process
    44  type IsolationConfig struct {
    45  	Cgroup      *cgroupConfig.Cgroup
    46  	CgroupPaths map[string]string
    47  }
    48  
    49  // RecoverableError wraps an error and marks whether it is recoverable and could
    50  // be retried or it is fatal.
    51  type RecoverableError struct {
    52  	Err         error
    53  	Recoverable bool
    54  }
    55  
    56  // NewRecoverableError is used to wrap an error and mark it as recoverable or
    57  // not.
    58  func NewRecoverableError(e error, recoverable bool) *RecoverableError {
    59  	return &RecoverableError{
    60  		Err:         e,
    61  		Recoverable: recoverable,
    62  	}
    63  }
    64  
    65  func (r *RecoverableError) Error() string {
    66  	return r.Err.Error()
    67  }
    68  
    69  // CheckResult encapsulates the result of a check
    70  type CheckResult struct {
    71  
    72  	// ExitCode is the exit code of the check
    73  	ExitCode int
    74  
    75  	// Output is the output of the check script
    76  	Output string
    77  
    78  	// Timestamp is the time at which the check was executed
    79  	Timestamp time.Time
    80  
    81  	// Duration is the time it took the check to run
    82  	Duration time.Duration
    83  
    84  	// Err is the error that a check returned
    85  	Err error
    86  }