exec

package
v0.0.0-...-1090150 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JOB_READY   = "ready"
	JOB_RUNNING = "running"
	JOB_FAILED  = "failed"
	JOB_SUCCESS = "success"
)

*************************************************************\ * Const * \*************************************************************

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor struct {
	WorkDir   string
	Inventory string
	Config    *conf.Config
	Jobs      map[string]*Job
	Lock      *sync.Mutex
}

*************************************************************\ * Executor * \************************************************************* Executor hold config path and content

func NewExecutor

func NewExecutor(path string) *Executor

NewExecutor will create ansible playbook executor based on config path

func (*Executor) LogDir

func (e *Executor) LogDir() string

LogDir return log directory of this executor (.pigsty/job by default)

func (*Executor) NewJob

func (e *Executor) NewJob(options ...JobOpts) *Job

NewJob will spawn new job and modify it with JobOpts

func (*Executor) Reload

func (e *Executor) Reload()

func (*Executor) StaticDir

func (e *Executor) StaticDir() string

Static return static resource of this executor (.pigsty/public by default)

type Job

type Job struct {
	ID       string                           `json:"id"`       // uuid v1
	Name     string                           `json:"name"`     // human readable job info
	Playbook string                           `json:"playbook"` // playbook name
	Limit    string                           `json:"limit"`    // limit execution targets
	Tags     []string                         `json:"tags"`     // execution tags
	LogPath  string                           `json:"log_path"` // write playbook log to ANSIBLE_LOG_PATH
	Status   string                           `json:"status"`   // ready | running | failed | success
	StartAt  time.Time                        `json:"start_at"` // job start at
	DoneAt   time.Time                        `json:"done_at"`  // job done at
	Command  string                           `json:"command"`  // job raw shell command
	CMD      *playbook.AnsiblePlaybookCmd     `json:"-"`        // ansible command
	Opts     *playbook.AnsiblePlaybookOptions `json:"-"`        // playbook options
	Exec     *Executor                        `json:"-"`        // Executor

	Stdout io.Writer `json:"-"` // write output to this
	Stderr io.Writer `json:"-"` // write error to this
	// contains filtered or unexported fields
}

*************************************************************\ * Job * \************************************************************* Job is spawned by executor

func (*Job) AsyncRun

func (j *Job) AsyncRun() string

AsyncRun will run tasks on background, a job id is returned

func (*Job) Cancel

func (j *Job) Cancel()

func (*Job) CreateLog

func (j *Job) CreateLog(name string) (io.WriteCloser, error)

CreateLog will create job log under executor's log directory

func (*Job) JSON

func (j *Job) JSON() string

func (*Job) MutexRun

func (j *Job) MutexRun(ctx context.Context) error

func (*Job) Run

func (j *Job) Run(ctx context.Context) error

Run will run given command under context

type JobOpts

type JobOpts func(*Job)

JobOpts will configure job

func WithAnsibleOpts

func WithAnsibleOpts(opts *playbook.AnsiblePlaybookOptions) JobOpts

WithAnsibleOpts will overwrite entire options, use with caution!

func WithExtraVars

func WithExtraVars(key string, value interface{}) JobOpts

WithExtraVars will add extra k-v into playbook's extra vars

func WithLimit

func WithLimit(limit string) JobOpts

WithLimit will set limit string to playbook

func WithLogPath

func WithLogPath(logPath string) JobOpts

func WithName

func WithName(name string) JobOpts

WithTags will set job name

func WithPlaybook

func WithPlaybook(playbook string) JobOpts

WithTags will set playbook names

func WithStderr

func WithStderr(w io.Writer) JobOpts

WithStderr will set stderr output

func WithStdout

func WithStdout(w io.Writer) JobOpts

WithStdout will set stdout

func WithTags

func WithTags(tags ...string) JobOpts

WithTags will set tasks tags to playbook

Jump to

Keyboard shortcuts

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