core

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 18 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSkippedExecution pass this error to `Execution.Stop` if you wish to mark
	// it as skipped.
	ErrSkippedExecution   = errors.New("skipped execution")
	ErrUnexpected         = errors.New("error unexpected, docker has returned exit code -1, maybe wrong user?")
	ErrMaxTimeRunning     = errors.New("the job has exceed the maximum allowed time running.")
	ErrLocalImageNotFound = errors.New("couldn't find image on the host")
)
View Source
var (
	ErrEmptyScheduler = errors.New("unable to start a empty scheduler.")
	ErrEmptySchedule  = errors.New("unable to add a job with a empty schedule.")
)

Functions

func BuildTestImage added in v0.3.9

func BuildTestImage(client *docker.Client, name string) error

Types

type BareJob

type BareJob struct {
	Schedule string
	Name     string
	Command  string
	// contains filtered or unexported fields
}

func (*BareJob) GetCommand

func (j *BareJob) GetCommand() string

func (*BareJob) GetName

func (j *BareJob) GetName() string

func (*BareJob) GetSchedule

func (j *BareJob) GetSchedule() string

func (*BareJob) Middlewares

func (c *BareJob) Middlewares() []Middleware

func (*BareJob) NotifyStart

func (j *BareJob) NotifyStart()

func (*BareJob) NotifyStop

func (j *BareJob) NotifyStop()

func (*BareJob) Running

func (j *BareJob) Running() int32

func (*BareJob) Use

func (c *BareJob) Use(ms ...Middleware)

type Context

type Context struct {
	Scheduler *Scheduler
	Logger    Logger
	Job       Job
	Execution *Execution
	// contains filtered or unexported fields
}

func NewContext

func NewContext(s *Scheduler, j Job, e *Execution) *Context

func (*Context) Log

func (c *Context) Log(msg string)

func (*Context) Next

func (c *Context) Next() error

func (*Context) Start

func (c *Context) Start()

func (*Context) Stop

func (c *Context) Stop(err error)

func (*Context) Warn added in v0.3.4

func (c *Context) Warn(msg string)

type ExecJob

type ExecJob struct {
	BareJob     `mapstructure:",squash"`
	Client      *docker.Client `json:"-"`
	Container   string
	User        string `default:"root"`
	TTY         bool   `default:"false"`
	Environment []string
	// contains filtered or unexported fields
}

func NewExecJob

func NewExecJob(c *docker.Client) *ExecJob

func (*ExecJob) Middlewares

func (c *ExecJob) Middlewares() []Middleware

func (*ExecJob) Run

func (j *ExecJob) Run(ctx *Context) error

func (*ExecJob) Use

func (c *ExecJob) Use(ms ...Middleware)

type Execution

type Execution struct {
	ID        string
	Date      time.Time
	Duration  time.Duration
	IsRunning bool
	Failed    bool
	Skipped   bool
	Error     error

	OutputStream, ErrorStream *circbuf.Buffer `json:"-"`
}

Execution contains all the information relative to a Job execution.

func NewExecution

func NewExecution() *Execution

NewExecution returns a new Execution, with a random ID

func (*Execution) Start

func (e *Execution) Start()

Start start the exection, initialize the running flags and the start date.

func (*Execution) Stop

func (e *Execution) Stop(err error)

Stop stops the executions, if a ErrSkippedExecution is given the exection is mark as skipped, if any other error is given the exection is mark as failed. Also mark the exection as IsRunning false and save the duration time

type Job

type Job interface {
	GetName() string
	GetSchedule() string
	GetCommand() string
	Middlewares() []Middleware
	Use(...Middleware)
	Run(*Context) error
	Running() int32
	NotifyStart()
	NotifyStop()
}

type LocalJob

type LocalJob struct {
	BareJob     `mapstructure:",squash"`
	Dir         string
	Environment []string
}

func NewLocalJob

func NewLocalJob() *LocalJob

func (*LocalJob) Middlewares

func (c *LocalJob) Middlewares() []Middleware

func (*LocalJob) Run

func (j *LocalJob) Run(ctx *Context) error

func (*LocalJob) Use

func (c *LocalJob) Use(ms ...Middleware)

type Logger

type Logger interface {
	Criticalf(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Noticef(format string, args ...interface{})
	Warningf(format string, args ...interface{})
}

type Middleware

type Middleware interface {
	// Run is called instead of the original `Job.Run`, you MUST call to `ctx.Run`
	// inside of the middleware `Run` function otherwise you will broken the
	// Job workflow.
	Run(*Context) error
	// ContinueOnStop,  If return true the Run function will be called even if
	// the execution is stopped
	ContinueOnStop() bool
}

Middleware can wrap any job execution, allowing to execution code before or/and after of each `Job.Run`

type RunJob

type RunJob struct {
	BareJob `mapstructure:",squash"`
	Client  *docker.Client `json:"-"`
	User    string         `default:"root"`

	TTY bool `default:"false"`

	// do not use bool values with "default:true" because if
	// user would set it to "false" explicitly, it still will be
	// changed to "true" https://github.com/mcuadros/ofelia/issues/135
	// so lets use strings here as workaround
	Delete string `default:"true"`
	Pull   string `default:"true"`

	Image       string
	Network     string
	Hostname    string
	Container   string
	Volume      []string
	Environment []string
	// contains filtered or unexported fields
}

func NewRunJob

func NewRunJob(c *docker.Client) *RunJob

func (*RunJob) Middlewares

func (c *RunJob) Middlewares() []Middleware

func (*RunJob) Run

func (j *RunJob) Run(ctx *Context) error

func (*RunJob) Use

func (c *RunJob) Use(ms ...Middleware)

type RunServiceJob

type RunServiceJob struct {
	BareJob `mapstructure:",squash"`
	Client  *docker.Client `json:"-"`
	User    string         `default:"root"`
	TTY     bool           `default:"false"`
	// do not use bool values with "default:true" because if
	// user would set it to "false" explicitly, it still will be
	// changed to "true" https://github.com/mcuadros/ofelia/issues/135
	// so lets use strings here as workaround
	Delete  string `default:"true"`
	Image   string
	Network string
}

func NewRunServiceJob

func NewRunServiceJob(c *docker.Client) *RunServiceJob

func (*RunServiceJob) Middlewares

func (c *RunServiceJob) Middlewares() []Middleware

func (*RunServiceJob) Run

func (j *RunServiceJob) Run(ctx *Context) error

func (*RunServiceJob) Use

func (c *RunServiceJob) Use(ms ...Middleware)

type Scheduler

type Scheduler struct {
	Jobs   []Job
	Logger Logger
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(l Logger) *Scheduler

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(j Job) error

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

func (*Scheduler) Middlewares

func (c *Scheduler) Middlewares() []Middleware

func (*Scheduler) Start

func (s *Scheduler) Start() error

func (*Scheduler) Stop

func (s *Scheduler) Stop() error

func (*Scheduler) Use

func (c *Scheduler) Use(ms ...Middleware)

Jump to

Keyboard shortcuts

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