jobfile

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrorHandlerStopName     = "Stop"
	ErrorHandlerBackoffName  = "Backoff"
	ErrorHandlerContinueName = "Continue"

	MaxBackoffWait = 8
)
View Source
const (
	PrefsSectName = "prefs"
	JobsSectName  = "jobs"
)
View Source
const RunRecOutputMaxLen = 1 << 20
View Source
const (
	TimeWildcard = "*"
)

Variables

View Source
var GlobalRunRecServerRegistry runRecServerRegistry
View Source
var JobStatuses = [...]JobStatus{
	JobGood,
	JobFailed,
	JobBackoff,
}

Functions

func SafeBytesToStr added in v1.4.0

func SafeBytesToStr(output []byte) (outputStr string, isBase64 bool)

func SerializeRunRec added in v1.4.0

func SerializeRunRec(rec RunRec, data ResultSinkDataParam) []byte

func ShouldLoadJobfile added in v1.3.0

func ShouldLoadJobfile(f *os.File, usr *user.User) (bool, error)

Types

type BackoffErrorHandler added in v1.4.0

type BackoffErrorHandler struct{}

func (BackoffErrorHandler) Handle added in v1.4.0

func (self BackoffErrorHandler) Handle(job *Job)

func (BackoffErrorHandler) String added in v1.4.0

func (self BackoffErrorHandler) String() string

type ContinueErrorHandler added in v1.4.0

type ContinueErrorHandler struct{}

func (ContinueErrorHandler) Handle added in v1.4.0

func (self ContinueErrorHandler) Handle(job *Job)

func (ContinueErrorHandler) String added in v1.4.0

func (self ContinueErrorHandler) String() string

type ErrorHandler

type ErrorHandler interface {
	Handle(job *Job)
	fmt.Stringer
}

func GetErrorHandler added in v1.4.0

func GetErrorHandler(name string) (ErrorHandler, error)

type FileJobOutputHandler added in v1.4.0

type FileJobOutputHandler struct {
	Where      string
	MaxAgeDays int
	Suffix     string
}

func (FileJobOutputHandler) String added in v1.4.0

func (self FileJobOutputHandler) String() string

func (FileJobOutputHandler) WriteOutput added in v1.4.0

func (self FileJobOutputHandler) WriteOutput(output []byte, jobName string,
	runTime time.Time)

type FilesystemResultSink added in v1.4.0

type FilesystemResultSink struct {
	Path       string              `yaml:"path"`
	Data       ResultSinkDataParam `yaml:"data"`
	MaxAgeDays int                 `yaml:"maxAgeDays"`
}

This result sink writes a run's stdout or stderr to disk.

Example: Consider FilesystemResultSink{Path: "/some/dir", DataRaw: ["stdout", "stderr"]}. For a job named "JobOne", this will result in a set of files like this:

  • /some/dir/
  • JobOne/
  • 1521318351.stdout
  • 1521318351.stderr
  • 1521318411.stdout
  • 1521318411.stderr
  • 1521318471.stdout
  • 1521318471.stderr

func (FilesystemResultSink) CheckParams added in v1.4.0

func (self FilesystemResultSink) CheckParams() error

func (FilesystemResultSink) Equals added in v1.4.0

func (self FilesystemResultSink) Equals(other ResultSink) bool

func (FilesystemResultSink) Handle added in v1.4.0

func (self FilesystemResultSink) Handle(rec RunRec)

func (FilesystemResultSink) String added in v1.4.0

func (self FilesystemResultSink) String() string

type FullTimeSpec

type FullTimeSpec struct {
	Sec  TimeSpec
	Min  TimeSpec
	Hour TimeSpec
	Mday TimeSpec
	Mon  TimeSpec
	Wday TimeSpec
}

func ParseFullTimeSpec

func ParseFullTimeSpec(s string) (*FullTimeSpec, error)

func (*FullTimeSpec) Derandomize added in v1.3.0

func (self *FullTimeSpec) Derandomize()

func (FullTimeSpec) Satisfied added in v1.3.1

func (self FullTimeSpec) Satisfied(t time.Time) bool

func (FullTimeSpec) String

func (self FullTimeSpec) String() string

type Job

type Job struct {
	// params
	Name            string
	Cmd             string
	FullTimeSpec    FullTimeSpec
	User            string
	ErrorHandler    ErrorHandler
	NotifyOnError   []ResultSink
	NotifyOnFailure []ResultSink
	NotifyOnSuccess []ResultSink

	// other dynamic stuff
	NextRunTime *time.Time
	Status      JobStatus
	LastRunTime time.Time
	Paused      bool
	// contains filtered or unexported fields
}

func (*Job) ShouldRun

func (job *Job) ShouldRun() bool

func (*Job) String

func (j *Job) String() string

type JobFile added in v1.3.0

type JobFile struct {
	Prefs UserPrefs
	Jobs  map[string]*Job
	Raw   JobFileRaw
}

func (*JobFile) InitResultSinks added in v1.4.0

func (self *JobFile) InitResultSinks()

type JobFileRaw added in v1.4.3

type JobFileRaw = JobFileV3Raw

func LoadJobfile added in v1.3.0

func LoadJobfile(f *os.File) (*JobFileRaw, error)

func NewEmptyRawJobFile added in v1.4.3

func NewEmptyRawJobFile() *JobFileRaw

type JobFileV1V2Raw added in v1.4.0

type JobFileV1V2Raw struct {
	Prefs UserPrefsV1V2Raw
	Jobs  []JobV1V2Raw
}

type JobFileV3Raw added in v1.4.0

type JobFileV3Raw struct {
	Version SemVer              `yaml:"version"`
	Prefs   UserPrefsV3Raw      `yaml:"prefs"`
	Jobs    map[string]JobV3Raw `yaml:"jobs"`
}

func (*JobFileV3Raw) Activate added in v1.4.3

func (self *JobFileV3Raw) Activate(usr *user.User) (*JobFile, error)

func (*JobFileV3Raw) Dup added in v1.4.3

func (self *JobFileV3Raw) Dup() *JobFileV3Raw

type JobOutputHandler added in v1.4.0

type JobOutputHandler interface {
	WriteOutput(output []byte, jobName string, runTime time.Time)
	fmt.Stringer
}

type JobRaw added in v1.4.3

type JobRaw = JobV3Raw

func NewRawJob added in v1.4.3

func NewRawJob() JobRaw

type JobStatus

type JobStatus uint8
const (
	JobGood JobStatus = iota
	JobFailed
	JobBackoff
)

func (JobStatus) String

func (s JobStatus) String() string

type JobV1V2Raw added in v1.4.0

type JobV1V2Raw struct {
	Name            string  `json:"name" yaml:"name"`
	Cmd             string  `json:"cmd" yaml:"cmd"`
	Time            string  `json:"time" yaml:"time"`
	OnError         *string `json:"onError" yaml:"onError"`
	NotifyOnSuccess *bool   `json:"notifyOnSuccess" yaml:"notifyOnSuccess"`
	NotifyOnError   *bool   `json:"notifyOnError" yaml:"notifyOnError"`
	NotifyOnFailure *bool   `json:"notifyOnFailure" yaml:"notifyOnFailure"`
}

type JobV3Raw added in v1.4.0

type JobV3Raw struct {
	Cmd             string          `json:"cmd" yaml:"cmd"`
	Time            string          `json:"time" yaml:"time"`
	OnError         *string         `json:"onError" yaml:"onError"`
	NotifyOnSuccess []ResultSinkRaw `json:"notifyOnSuccess" yaml:"notifyOnSuccess"`
	NotifyOnError   []ResultSinkRaw `json:"notifyOnError" yaml:"notifyOnError"`
	NotifyOnFailure []ResultSinkRaw `json:"notifyOnFailure" yaml:"notifyOnFailure"`
}

func (JobV3Raw) ToJob added in v1.4.0

func (self JobV3Raw) ToJob(usr *user.User, dest *Job) error

type NopJobOutputHandler added in v1.4.0

type NopJobOutputHandler struct{}

func (NopJobOutputHandler) String added in v1.4.0

func (self NopJobOutputHandler) String() string

func (NopJobOutputHandler) WriteOutput added in v1.4.0

func (self NopJobOutputHandler) WriteOutput(output []byte, jobName string,
	runTime time.Time)

type OneValTimeSpec

type OneValTimeSpec struct {
	// contains filtered or unexported fields
}

func (OneValTimeSpec) Derandomize added in v1.4.0

func (self OneValTimeSpec) Derandomize()

func (OneValTimeSpec) IsWildcard added in v1.3.1

func (self OneValTimeSpec) IsWildcard() bool

func (OneValTimeSpec) Satisfied

func (self OneValTimeSpec) Satisfied(v int) bool

func (OneValTimeSpec) String

func (self OneValTimeSpec) String() string

type ProgramResultSink added in v1.4.0

type ProgramResultSink struct {
	Path                string `yaml:"path"`
	RunRecFormatVersion SemVer `yaml:"runRecFormatVersion"`
}

func (ProgramResultSink) CheckParams added in v1.4.0

func (self ProgramResultSink) CheckParams() error

func (ProgramResultSink) Equals added in v1.4.0

func (self ProgramResultSink) Equals(other ResultSink) bool

func (ProgramResultSink) Handle added in v1.4.0

func (self ProgramResultSink) Handle(rec RunRec)

func (ProgramResultSink) String added in v1.4.0

func (self ProgramResultSink) String() string

type RandomTimeSpec added in v1.3.0

type RandomTimeSpec struct {
	// contains filtered or unexported fields
}

A time spec that chooses (pseudo-)randomly from a set of values. Each value in that set has an (approximately) equal chance of getting picked.

func (*RandomTimeSpec) Derandomize added in v1.3.0

func (self *RandomTimeSpec) Derandomize()

Pick a random value, and remember it so that it can be used by the method Satisfied.

The method Satisfied will panic unless this method has been called.

If this method has already been called, calling it again has no effect.

func (RandomTimeSpec) IsWildcard added in v1.3.1

func (self RandomTimeSpec) IsWildcard() bool

func (RandomTimeSpec) PickedValue added in v1.3.0

func (self RandomTimeSpec) PickedValue() *int

Get the picked value. If Derandomize has never been called, returns nil.

func (RandomTimeSpec) Satisfied added in v1.3.0

func (self RandomTimeSpec) Satisfied(val int) bool

Get whether the time spec is satisfied by val.

If Derandomize has never been called, this method will panic.

func (RandomTimeSpec) String added in v1.3.0

func (self RandomTimeSpec) String() string

type ResultSink added in v1.4.0

type ResultSink interface {
	/*
		Do something with the given run record.
	*/
	Handle(runRec RunRec)

	/*
		Check for problems with the params.  This is called just after
		deserialization from a jobfile.
	*/
	CheckParams() error

	Equals(other ResultSink) bool

	fmt.Stringer
}

A result sink is an object that does something with the results of a job run.

func MakeResultSinkFromConfig added in v1.4.0

func MakeResultSinkFromConfig(config ResultSinkRaw) (ResultSink, error)

type ResultSinkDataParam added in v1.4.0

type ResultSinkDataParam uint
const (
	RESULT_SINK_DATA_STDOUT ResultSinkDataParam = 1 << iota
	RESULT_SINK_DATA_STDERR
)

func (ResultSinkDataParam) Contains added in v1.4.0

func (self ResultSinkDataParam) Contains(value ResultSinkDataParam) bool

func (*ResultSinkDataParam) UnmarshalYAML added in v1.4.0

func (self *ResultSinkDataParam) UnmarshalYAML(unmarshal func(interface{}) error) error

type ResultSinkRaw added in v1.4.0

type ResultSinkRaw map[string]interface{}

type RunLog added in v1.3.0

type RunLog interface {
	/*
	    	There are two ways to use this method.

	    	"GetFromTime(t)": Get all entries for runs that started no
	    	later than t.

	    	"GetFromTime(t1, t2)": Get all entries that started no later
	    	than t1 but later than t2.

	   The entries are returned in order of start time, descending.
	*/
	GetFromTime(maxTime time.Time, minTime ...time.Time) ([]*RunLogEntry, error)

	/*
		There are two ways to use this method.

		"GetFromIndex(i)": Get all entries with index >= i.

		"GetFromIndex(i, j)": Get all entries with index >= i but
		< j.
	*/
	GetFromIndex(minIdx int, maxIdx ...int) ([]*RunLogEntry, error)

	/*
	   Get all entries.
	*/
	GetAll() ([]*RunLogEntry, error)

	Len() int

	Put(entry RunLogEntry) error
}

This is a database of job runs. It may be backed by a file, or it may not: this depends on the user's preferences specified in the jobfile.

func NewFileRunLog added in v1.3.0

func NewFileRunLog(filePath string, maxFileLen int64,
	maxHistories int) (RunLog, error)

func NewMemOnlyRunLog added in v1.3.0

func NewMemOnlyRunLog(maxLen int) RunLog

type RunLogEntry added in v1.3.0

type RunLogEntry struct {
	JobName string
	Time    time.Time
	Fate    common.SubprocFate
	Result  JobStatus
}

type RunLogRaw added in v1.4.0

type RunLogRaw struct {
	Type string `yaml:"type"` // "file" or "memory"

	// fields for type == "memory
	MaxLen *int `yaml:"maxLen"`

	// fields for type == "file":
	Path         *string `yaml:"path"`
	MaxFileLen   *string `yaml:"maxFileLen"`
	MaxHistories *int    `yaml:"maxHistories"`
}

func (RunLogRaw) ToRunLog added in v1.4.0

func (self RunLogRaw) ToRunLog() (RunLog, error)

type RunRec

type RunRec struct {
	Job       *Job
	RunTime   time.Time
	NewStatus JobStatus
	Stdout    []byte
	Stderr    []byte
	Fate      common.SubprocFate
	Err       error
}

func (*RunRec) Describe

func (rec *RunRec) Describe() string

type SemVer added in v1.4.0

type SemVer struct {
	Major uint
	Minor uint
	Patch uint
}

func (SemVer) Compare added in v1.4.0

func (self SemVer) Compare(other SemVer) int

func (SemVer) IsZero added in v1.4.0

func (self SemVer) IsZero() bool

func (SemVer) MarshalJSON added in v1.4.0

func (self SemVer) MarshalJSON() ([]byte, error)

func (SemVer) MarshalYAML added in v1.4.0

func (self SemVer) MarshalYAML() (interface{}, error)

func (SemVer) String added in v1.4.0

func (self SemVer) String() string

func (*SemVer) UnmarshalYAML added in v1.4.0

func (self *SemVer) UnmarshalYAML(unmarshal func(interface{}) error) error

type SetTimeSpec

type SetTimeSpec struct {
	// contains filtered or unexported fields
}

func (SetTimeSpec) Derandomize added in v1.4.0

func (self SetTimeSpec) Derandomize()

func (SetTimeSpec) IsWildcard added in v1.3.1

func (self SetTimeSpec) IsWildcard() bool

func (SetTimeSpec) Satisfied

func (self SetTimeSpec) Satisfied(v int) bool

func (SetTimeSpec) String

func (self SetTimeSpec) String() string

type SocketResultSink added in v1.4.0

type SocketResultSink struct {
	Proto   string              `yaml:"proto"`
	Address string              `yaml:"address"`
	Data    ResultSinkDataParam `yaml:"data"`
}

func (SocketResultSink) CheckParams added in v1.4.0

func (self SocketResultSink) CheckParams() error

func (SocketResultSink) Equals added in v1.4.0

func (self SocketResultSink) Equals(other ResultSink) bool

func (SocketResultSink) Handle added in v1.4.0

func (self SocketResultSink) Handle(runRec RunRec)

func (SocketResultSink) String added in v1.4.0

func (self SocketResultSink) String() string

type StdoutResultSink added in v1.4.0

type StdoutResultSink struct {
	Data ResultSinkDataParam `yaml:"data"`
}

This result sink sends run results to jobberrunner's stdout.

func (StdoutResultSink) CheckParams added in v1.4.0

func (self StdoutResultSink) CheckParams() error

func (StdoutResultSink) Equals added in v1.4.0

func (self StdoutResultSink) Equals(other ResultSink) bool

func (StdoutResultSink) Handle added in v1.4.0

func (self StdoutResultSink) Handle(rec RunRec)

func (StdoutResultSink) String added in v1.4.0

func (self StdoutResultSink) String() string

type StopErrorHandler added in v1.4.0

type StopErrorHandler struct{}

func (StopErrorHandler) Handle added in v1.4.0

func (self StopErrorHandler) Handle(job *Job)

func (StopErrorHandler) String added in v1.4.0

func (self StopErrorHandler) String() string

type SystemEmailResultSink added in v1.4.0

type SystemEmailResultSink struct{}

func (SystemEmailResultSink) CheckParams added in v1.4.0

func (self SystemEmailResultSink) CheckParams() error

func (SystemEmailResultSink) Equals added in v1.4.0

func (self SystemEmailResultSink) Equals(other ResultSink) bool

func (SystemEmailResultSink) Handle added in v1.4.0

func (self SystemEmailResultSink) Handle(rec RunRec)

func (SystemEmailResultSink) String added in v1.4.0

func (self SystemEmailResultSink) String() string

type TimeSpec

type TimeSpec interface {
	fmt.Stringer
	Satisfied(int) bool
	IsWildcard() bool
	Derandomize()
}

type UserPrefs

type UserPrefs struct {
	RunLog  RunLog
	LogPath string // for error msgs etc.  May be "".
}

func (*UserPrefs) String added in v1.4.0

func (self *UserPrefs) String() string

type UserPrefsV1V2Raw added in v1.4.0

type UserPrefsV1V2Raw struct {
	LogPath       *string    `yaml:"logPath"`
	RunLog        *RunLogRaw `yaml:"runLog"`
	NotifyProgram *string    `yaml:"notifyProgram"`
}

type UserPrefsV3Raw added in v1.4.0

type UserPrefsV3Raw struct {
	LogPath *string    `yaml:"logPath"`
	RunLog  *RunLogRaw `yaml:"runLog"`
}

func (UserPrefsV3Raw) ToPrefs added in v1.4.0

func (self UserPrefsV3Raw) ToPrefs(usr *user.User, dest *UserPrefs) error

type WildcardTimeSpec

type WildcardTimeSpec struct{}

func (WildcardTimeSpec) Derandomize added in v1.4.0

func (self WildcardTimeSpec) Derandomize()

func (WildcardTimeSpec) IsWildcard added in v1.3.1

func (self WildcardTimeSpec) IsWildcard() bool

func (WildcardTimeSpec) Satisfied

func (self WildcardTimeSpec) Satisfied(v int) bool

func (WildcardTimeSpec) String

func (self WildcardTimeSpec) String() string

Jump to

Keyboard shortcuts

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