job

package
v0.0.0-...-4dbe43f Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "02.01.2006 15:04 Uhr"

Variables

View Source
var ErrInvalidExecutionPlan = errors.New("not a valid ExecutionPlan")

Functions

func IsPossible

func IsPossible(j Job) (bool, error)

func PrintDryRunTag

func PrintDryRunTag()

func PrintHeader

func PrintHeader(j Job, next *time.Time)

func PrintSuccessful

func PrintSuccessful(message string, duration *time.Duration)

func PrintUnsuccessful

func PrintUnsuccessful(message string, duration *time.Duration)

func Timeago

func Timeago(date time.Time) string

Types

type ExecutionOptions

type ExecutionOptions struct {
	ExecutionPlan ExecutionPlan
	Delay         bool
	Wait          bool

	DryRun  bool
	Verbose bool
}

type ExecutionPlan

type ExecutionPlan uint8

ENUM(skip, logDone, execute)

const (
	// ExecutionPlanSkip is a ExecutionPlan of type Skip.
	ExecutionPlanSkip ExecutionPlan = iota
	// ExecutionPlanLogDone is a ExecutionPlan of type LogDone.
	ExecutionPlanLogDone
	// ExecutionPlanExecute is a ExecutionPlan of type Execute.
	ExecutionPlanExecute
)

func ParseExecutionPlan

func ParseExecutionPlan(name string) (ExecutionPlan, error)

ParseExecutionPlan attempts to convert a string to a ExecutionPlan.

func (ExecutionPlan) IsValid

func (x ExecutionPlan) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (ExecutionPlan) String

func (x ExecutionPlan) String() string

String implements the Stringer interface.

type Factory

type Factory struct{}

func (Factory) GetFromFile

func (x Factory) GetFromFile(filename string) (Job, error)

type FeedDownloadJob

type FeedDownloadJob struct {
	Meta Metadata `yaml:"metadata"`

	RemoteURL string `yaml:"remote-url"`
	LocalDir  string `yaml:"local-dir"`
}

func LoadFeedDownloadJobFromFile

func LoadFeedDownloadJobFromFile(filename string) (*FeedDownloadJob, error)

func (*FeedDownloadJob) Execute

func (x *FeedDownloadJob) Execute(options ExecutionOptions) error

func (FeedDownloadJob) IsPossible

func (x FeedDownloadJob) IsPossible() (bool, error)

func (*FeedDownloadJob) Metadata

func (x *FeedDownloadJob) Metadata() Metadata

func (*FeedDownloadJob) Post

func (x *FeedDownloadJob) Post() error

func (*FeedDownloadJob) Pre

func (x *FeedDownloadJob) Pre() error

func (*FeedDownloadJob) WithFilename

func (x *FeedDownloadJob) WithFilename(filename string) *FeedDownloadJob

type HTTPDownloadJob

type HTTPDownloadJob struct {
	Meta Metadata `yaml:"metadata"`

	Files []struct {
		RemoteURL     string `yaml:"remote-url"`
		LocalDir      string `yaml:"local-dir"`
		LocalFilename string `yaml:"local-filename"`
	} `yaml:"files"`
}

func LoadHTTPDownloadJobFromFile

func LoadHTTPDownloadJobFromFile(filename string) (*HTTPDownloadJob, error)

func (*HTTPDownloadJob) Execute

func (x *HTTPDownloadJob) Execute(options ExecutionOptions) error

func (HTTPDownloadJob) IsPossible

func (x HTTPDownloadJob) IsPossible() (bool, error)

func (*HTTPDownloadJob) Metadata

func (x *HTTPDownloadJob) Metadata() Metadata

func (*HTTPDownloadJob) Post

func (x *HTTPDownloadJob) Post() error

func (*HTTPDownloadJob) Pre

func (x *HTTPDownloadJob) Pre() error

func (*HTTPDownloadJob) WithFilename

func (x *HTTPDownloadJob) WithFilename(filename string) *HTTPDownloadJob

type ImpossibleJobError

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

func NewImpossibleJobError

func NewImpossibleJobError(err error, fixable bool) ImpossibleJobError

func NewImpossibleJobErrorFromProcessResult

func NewImpossibleJobErrorFromProcessResult(result *script.ProcessResult) ImpossibleJobError

func (*ImpossibleJobError) As

func (x *ImpossibleJobError) As(t any) bool

func (ImpossibleJobError) Error

func (x ImpossibleJobError) Error() string

func (*ImpossibleJobError) Is

func (x *ImpossibleJobError) Is(target error) bool

func (ImpossibleJobError) IsFixable

func (x ImpossibleJobError) IsFixable() bool

func (ImpossibleJobError) Unwrap

func (x ImpossibleJobError) Unwrap() error

type Job

type Job interface {
	Metadata() Metadata

	// Execution
	IsPossible() (bool, error)
	Pre() error
	Execute(options ExecutionOptions) error
	Post() error
}

type Metadata

type Metadata struct {
	JobType     string `yaml:"type"`
	Filename    string
	Name        string   `yaml:"name,omitempty"`
	Description string   `yaml:"description,omitempty"`
	Unattended  *bool    `yaml:"unattended,omitempty"`
	Enabled     *bool    `yaml:"enabled,omitempty"`
	Next        string   `yaml:"next,omitempty"`
	Possible    []string `yaml:"possible,omitempty"`
	Sudo        *bool    `yaml:"sudo,omitempty"`

	Timeout time.Duration // TODO implement

	Weight *int `yaml:"weight,omitempty"`

	Output string `yaml:"output,omitempty"`
	Pre    struct {
		Command string `yaml:"command,omitempty"`
	} `yaml:"pre,omitempty"`
	Post struct {
		Command string `yaml:"command,omitempty"`
	} `json:"post,omitempty"`
}

func (Metadata) GetWeight

func (x Metadata) GetWeight() int

func (Metadata) IsDisabled

func (x Metadata) IsDisabled() bool

func (Metadata) IsEnabled

func (x Metadata) IsEnabled() bool

func (Metadata) IsUnattended

func (x Metadata) IsUnattended() bool

type OpenJob

type OpenJob struct {
	Meta Metadata `yaml:"metadata"`

	Wait bool `yaml:"wait,omitempty"`

	Targets []string `yaml:"targets"`
}

func LoadOpenJobFromFile

func LoadOpenJobFromFile(filename string) (*OpenJob, error)

func (*OpenJob) Execute

func (x *OpenJob) Execute(options ExecutionOptions) error

func (OpenJob) IsPossible

func (x OpenJob) IsPossible() (bool, error)

func (*OpenJob) Metadata

func (x *OpenJob) Metadata() Metadata

func (*OpenJob) Post

func (x *OpenJob) Post() error

func (*OpenJob) Pre

func (x *OpenJob) Pre() error

func (*OpenJob) WithFilename

func (x *OpenJob) WithFilename(filename string) Job

type Pool

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

func NewJobPool

func NewJobPool() *Pool

func NewJobPoolWithJobs

func NewJobPoolWithJobs(jobs []Job) *Pool

func (*Pool) AddJob

func (x *Pool) AddJob(job Job) *Pool

func (*Pool) AttendedOnly

func (x *Pool) AttendedOnly() *Pool

func (*Pool) ByWeight

func (x *Pool) ByWeight() *Pool

func (*Pool) EnabledOnly

func (x *Pool) EnabledOnly() *Pool

func (*Pool) Jobs

func (x *Pool) Jobs() []Job

func (Pool) NeedsSudo

func (x Pool) NeedsSudo() bool

NeedsSudo checks if any of the Jobs in the Pool needs privileged access

func (*Pool) PossibleOnly

func (x *Pool) PossibleOnly() *Pool

func (*Pool) PossibleOrFixableOnly

func (x *Pool) PossibleOrFixableOnly() *Pool

func (*Pool) RequiredOnly

func (x *Pool) RequiredOnly(next func(j Job) time.Time) *Pool

func (*Pool) SortedBy

func (x *Pool) SortedBy(lessFunc func(j1, j2 Job) bool) *Pool

func (*Pool) UnattendedOnly

func (x *Pool) UnattendedOnly() *Pool

type ShellJob

type ShellJob struct {
	Meta Metadata `yaml:"metadata"`

	Wait bool `yaml:"wait"`

	Exec       string `yaml:"execute"`
	ExecDryRun string `yaml:"execute-dry-run,omitempty"`
}

func LoadShellJobFromFile

func LoadShellJobFromFile(filename string) (*ShellJob, error)

func (*ShellJob) Execute

func (x *ShellJob) Execute(options ExecutionOptions) error

func (ShellJob) IsPossible

func (x ShellJob) IsPossible() (bool, error)

func (*ShellJob) Metadata

func (x *ShellJob) Metadata() Metadata

func (*ShellJob) Post

func (x *ShellJob) Post() error

func (*ShellJob) Pre

func (x *ShellJob) Pre() error

func (*ShellJob) WithFilename

func (x *ShellJob) WithFilename(filename string) Job

type TextJob

type TextJob struct {
	Meta Metadata `yaml:"metadata"`

	Wait bool `yaml:"wait,omitempty"`

	Text string `yaml:"text,omitempty"`
}

func LoadTextJobFromFile

func LoadTextJobFromFile(filename string) (*TextJob, error)

func (*TextJob) Execute

func (x *TextJob) Execute(options ExecutionOptions) error

func (TextJob) IsPossible

func (x TextJob) IsPossible() (bool, error)

func (*TextJob) Metadata

func (x *TextJob) Metadata() Metadata

func (*TextJob) Post

func (x *TextJob) Post() error

func (*TextJob) Pre

func (x *TextJob) Pre() error

func (*TextJob) WithFilename

func (x *TextJob) WithFilename(filename string) Job

Jump to

Keyboard shortcuts

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