jobs

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MatrixInstancePrefix = "PGQ_INSTANCE"

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(logger *zap.SugaredLogger, level zap.AtomicLevel)

Types

type Alert

type Alert struct {
	AlertType string `yaml:"type"`
	Command   string `yaml:"command"`
}

type Alerts

type Alerts []Alert

type Checks

type Checks []Command

type Command

type Command struct {
	Name   string `yaml:"name"`
	Type   string `yaml:"type"`
	Inline string `yaml:"inline,omitempty"`
	// Home (~) is not resolved
	File string `yaml:"file,omitempty"`

	Rc     int               `yaml:"-"`
	Test   string            `yaml:"test,omitempty"`
	Matrix map[string]string `yaml:"matrix,omitempty"`
	// contains filtered or unexported fields
}

func (*Command) CleanTempFile

func (c *Command) CleanTempFile()

func (Command) GetCommands

func (c Command) GetCommands() string

func (*Command) Run

func (c *Command) Run(conns Connections, args InstanceArguments) (err error)

func (*Command) RunOsCommand

func (c *Command) RunOsCommand(args InstanceArguments) (err error)

func (Command) ScriptBody

func (c Command) ScriptBody() (scriptBody string)

ScriptBody does the exact opposite of ScriptFile. For Command.File it reads the contents. In other situations it just returns Command.Inline. This is wat is used to run commands on database connections.

func (*Command) ScriptFile

func (c *Command) ScriptFile() (scriptFile string)

ScriptFile returns a path to the script holding the command. This could be the symlink evaluated version of Command.File. Or this could be an executable temporary file with Command.Inline as contents. This is wat is used to run shell commands

func (Command) Verify

func (c Command) Verify(stepName string, conns Connections) (errs []error)

func (Command) VerifyScriptFile

func (c Command) VerifyScriptFile() (err error)

type Commands

type Commands []*Command

func (Commands) Clone

func (cs Commands) Clone() (clone Commands)

func (Commands) Rc

func (cs Commands) Rc() (rc int)

func (*Commands) Run

func (cs *Commands) Run(conns Connections, args InstanceArguments) (err error)

func (Commands) StdErr

func (cs Commands) StdErr() (stdErr Result)

func (Commands) StdOut

func (cs Commands) StdOut() (stdOut Result)

func (Commands) Verify

func (cs Commands) Verify(stepName string, conns Connections) (errs []error)

type Config

type Config struct {
	Steps      Steps       `yaml:"steps"`
	Checks     Commands    `yaml:"checks"`
	Target     Target      `yaml:"target"`
	Conns      Connections `yaml:"connections"`
	Alert      []Alert     `yaml:"alerts"`
	Log        []Log       `yaml:"log"`
	Debug      bool        `yaml:"debug"`
	Parallel   int         `yaml:"parallel"`
	Workdir    string      `yaml:"workdir"`
	EtcdConfig etcd.Config `yaml:"etcdConfig"`
	Timeout    string      `yaml:"timeout"`
}

func (Config) GetTimeoutContext

func (c Config) GetTimeoutContext(parentContext context.Context) (context.Context, context.CancelFunc)

func (*Config) Initialize

func (c *Config) Initialize()

func (Config) String

func (c Config) String() string

func (Config) Verify

func (c Config) Verify()

type Connections

type Connections map[string]pg.Conn

func (Connections) Execute

func (cs Connections) Execute(connName string, query string, args InstanceArguments) (result Result, err error)

type Handler

type Handler struct {
	Config  Config
	Steps   Steps
	Runners Runners
	ToDo    chan Work
	Done    chan Work
}

func NewHandler

func NewHandler(c Config) Handler

func (*Handler) RunChecks

func (h *Handler) RunChecks()

func (*Handler) RunSteps

func (h *Handler) RunSteps()

func (*Handler) VerifyConfig

func (h *Handler) VerifyConfig()

func (Handler) VerifyRoles

func (h Handler) VerifyRoles() bool

type Instance added in v0.1.3

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

func NewInstance added in v0.1.3

func NewInstance(args InstanceArguments, commands Commands) *Instance

func (Instance) Clone added in v0.1.3

func (i Instance) Clone() (clone *Instance)

func (Instance) Name added in v0.1.3

func (i Instance) Name() string

func (Instance) StdErr added in v0.1.3

func (i Instance) StdErr() (r Result)

func (Instance) StdOut added in v0.1.3

func (i Instance) StdOut() (r Result)

type InstanceArguments

type InstanceArguments map[string]string

InstanceArguments are key=value pairs which is extrapolated from MatrixArgs One InstanceArguments is parsed to a step instance

func (InstanceArguments) AsEnv

func (ias InstanceArguments) AsEnv() []string

func (InstanceArguments) Clone

func (ias InstanceArguments) Clone() (newMia InstanceArguments)

func (InstanceArguments) ParseQuery

func (ias InstanceArguments) ParseQuery(query string) (parsedQuery string, args []interface{})

ParseQuery can take a query with named arguments and convert it into a query with numbered arguments. Inspired by https://github.com/jackc/pgx/issues/387#issuecomment-798348824

func (InstanceArguments) String

func (ias InstanceArguments) String() string

type Instances

type Instances map[string]*Instance

func (Instances) Clone added in v0.1.3

func (is Instances) Clone() (clone Instances)

func (Instances) Done added in v0.1.3

func (is Instances) Done() bool

func (Instances) Rc added in v0.1.3

func (is Instances) Rc() (rc int)

func (Instances) StdErr added in v0.1.3

func (is Instances) StdErr() (r Result)

func (Instances) StdOut added in v0.1.3

func (is Instances) StdOut() (r Result)

type Log

type Log struct {
	LogType string `yaml:"type"`
	Command string `yaml:"command"`
}

type Logs

type Logs []Log

type MatrixArgValues

type MatrixArgValues []string

MatrixArgValues is an array for all the values that one MatrixArg could have

func (MatrixArgValues) Explode

func (mavs MatrixArgValues) Explode(key string, collected []InstanceArguments) (exploded []InstanceArguments)

type MatrixArgs

type MatrixArgs map[string]MatrixArgValues

MatrixArgs is a map of Matrix Arguments. The keys are the names of the argument and - will be prefixed and uppercased when set for shell commands - will be changed into numbered args when set for sql commands

func (MatrixArgs) Instances

func (mas MatrixArgs) Instances() (ias []InstanceArguments)

type Result

type Result []ResultLine

func NewResult

func NewResult(lines []string) (result Result)

func NewResultFromString

func NewResultFromString(lines string) (result Result)

func (Result) Contains

func (r Result) Contains(part string) bool

func (Result) ContainsLine

func (r Result) ContainsLine(line string) bool

func (Result) RegExpContains

func (r Result) RegExpContains(exp string) bool

func (Result) String added in v0.1.3

func (r Result) String() string

type ResultLine

type ResultLine string

func (ResultLine) Contains

func (r ResultLine) Contains(part string) bool

type Runner

type Runner struct {
	Steps Steps
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(h *Handler, index int) *Runner

func (*Runner) Run

func (r *Runner) Run()

type Runners

type Runners []*Runner

func (Runners) Done

func (rs Runners) Done() bool

type Step

type Step struct {
	Commands Commands `yaml:"commands"`
	Depends  []string `yaml:"depends,omitempty"`

	When      []string   `yaml:"when,omitempty"`
	Matrix    MatrixArgs `yaml:"matrix,omitempty"`
	Instances Instances  `yaml:"-"`
	// contains filtered or unexported fields
}

func (Step) Clone

func (s Step) Clone() *Step

func (*Step) Done

func (s *Step) Done() bool

func (Step) GetInstances

func (s Step) GetInstances() Instances

func (*Step) Initialize added in v0.1.3

func (s *Step) Initialize()

func (*Step) InstanceFinished

func (s *Step) InstanceFinished(instance string) bool

func (Step) Rc

func (s Step) Rc() int

func (Step) Ready

func (s Step) Ready() bool

func (*Step) SetInstances

func (s *Step) SetInstances()

func (Step) StdErr

func (s Step) StdErr() Result

func (Step) StdOut

func (s Step) StdOut() Result

func (Step) Waiting

func (s Step) Waiting() bool

type Steps

type Steps map[string]*Step

func (Steps) CheckWhen

func (ss Steps) CheckWhen(all Handler, stepName string) (bool, error)

func (Steps) Clone

func (ss Steps) Clone() Steps

func (Steps) GetNumInstances

func (ss Steps) GetNumInstances() int

func (Steps) GetReadySteps

func (ss Steps) GetReadySteps() (ready []string)

func (*Steps) Initialize

func (ss *Steps) Initialize()

func (*Steps) InstanceFinished added in v0.1.3

func (ss *Steps) InstanceFinished(w Work)

func (Steps) NumWaiting

func (ss Steps) NumWaiting() (numWaiting int)

func (Steps) Verify

func (ss Steps) Verify(conns Connections) (errs []error)

type Target

type Target struct {
	Role         string `yaml:"role"`
	Distribution string `yaml:"distribution"`
	Repeat       int    `yaml:"repeat"`
	Delay        int    `yaml:"delay"`
}

type Work

type Work struct {
	Step   string
	ArgKey string
}

Jump to

Keyboard shortcuts

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