task

package
v0.0.0-...-c57eb44 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const UUID = "uuid"

UUID indentifier for tasks

Variables

View Source
var ActionRecomposatorRegistry map[string]func(docker *client.Client, project string, cfg map[string]interface{}) (ActionRecomposator, error)
View Source
var ActionValidatorRegistry map[string]func(map[string]interface{}) (ActionValidator, error)
View Source
var ActionsRegistry map[string]func() action.Action

ActionsRegistry register all Action implementation

View Source
var IsLabelValid = regexp.MustCompile(`^[a-z0-9]+([.-][a-z0-9]+)*$`).MatchString

IsLabelValid is a simple function used to check validity of both key and value pairs in labels

View Source
var RunRegistry map[string]func() _run.Run

RunRegistry register all Run implementation

Functions

This section is empty.

Types

type Action

type Action interface {
	// Validate if attributes are correct
	Validate() error
	// Run with a context, a working directory and environments variables.
	Up(pwd string, environments map[string]string, runID int) (run.Run, error)
	// RegisteredName is registered name
	RegisteredName() string
}

Action interface describe behavior of a job

type ActionRecomposator

type ActionRecomposator interface {
	RecomposeAction(a Action) (Action, error)
}

type ActionValidator

type ActionValidator interface {
	ValidateAction(a Action) []error
}

type DummyAction

type DummyAction struct {
	Name     string        `json:"name"`
	Wait     time.Duration `json:"wait"`
	Counter  int64         `json:"counter"`
	ExitCode int           `json:"exit_code"`
	// contains filtered or unexported fields
}

DummyAction is the most basic action, used for tests and illustration purpose

func (*DummyAction) RegisteredName

func (da *DummyAction) RegisteredName() string

func (*DummyAction) Up

func (da *DummyAction) Up(pwd string, environments map[string]string, runID int) (run.Run, error)

Run action interface implementation

func (*DummyAction) Validate

func (da *DummyAction) Validate() error

Validate action interface implementation

type DummyActionValidator

type DummyActionValidator struct{}

func (*DummyActionValidator) ValidateAction

func (d *DummyActionValidator) ValidateAction(a Action) []error

type DummyRun

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

func (*DummyRun) Data

func (r *DummyRun) Data() run.Data

func (DummyRun) Down

func (r DummyRun) Down() error

func (*DummyRun) RegisteredName

func (r *DummyRun) RegisteredName() string

func (*DummyRun) RunnerID

func (r *DummyRun) RunnerID() (string, error)

func (*DummyRun) Status

func (r *DummyRun) Status() (run.Status, int, error)

func (*DummyRun) Wait

func (r *DummyRun) Wait(ctx context.Context) (_status.Status, error)

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type RawTask

type RawTask struct {
	Start           time.Time                  `json:"start"`              // Start time
	MaxWaitTime     Duration                   `json:"max_wait_time"`      // Max wait time before starting Action
	MaxExectionTime Duration                   `json:"max_execution_time"` // Max execution time
	CPU             int                        `json:"cpu"`                // CPU quota
	RAM             int                        `json:"ram"`                // RAM quota
	Action          map[string]json.RawMessage `json:"action"`             // Action is an abstract, the thing to do
	Id              uuid.UUID                  `json:"id"`                 // Id
	Status          status.Status              `json:"status"`             // Status
	Mtime           time.Time                  `json:"mtime"`              // Modified time
	Owner           string                     `json:"owner"`              // Owner
	Retry           int                        `json:"retry"`              // Number of retry before crash
	Every           time.Duration              `json:"every"`              // Periodic execution. Exclusive with Cron
	Cron            string                     `json:"cron"`               // Cron definition. Exclusive with Every
	Environments    map[string]string          `json:"environments,omitempty"`
	Run             map[string]json.RawMessage `json:"run"`
	RunCounter      int                        `json:"run_counter"`
	Runs            []_run.Data                `json:"runs"`
	Labels          map[string]string          `json:"labels"`
}

type Recomposator

type Recomposator struct {
	Recomposators map[string]map[string]interface{} `yaml:"recomposators"`
	// contains filtered or unexported fields
}

func (*Recomposator) RecomposeAction

func (r *Recomposator) RecomposeAction(a Action) (Action, error)

func (*Recomposator) Register

func (r *Recomposator) Register(docker *client.Client, projet string) error

type Resp

type Resp struct {
	Start           time.Time         `json:"start"`              // Start time
	MaxWaitTime     time.Duration     `json:"max_wait_time"`      // Max wait time before starting Action
	MaxExectionTime time.Duration     `json:"max_execution_time"` // Max execution time
	CPU             int               `json:"cpu"`                // CPU quota
	RAM             int               `json:"ram"`                // RAM quota
	Id              uuid.UUID         `json:"id"`                 // Id
	Status          status.Status     `json:"status"`             // Status
	Mtime           time.Time         `json:"mtime"`              // Modified time
	Owner           string            `json:"owner"`              // Owner
	Retry           int               `json:"retry"`              // Number of retry before crash
	Every           time.Duration     `json:"every"`              // Periodic execution. Exclusive with Cron
	Cron            string            `json:"cron"`               // Cron definition. Exclusive with Every
	Environments    map[string]string `json:"environments,omitempty"`
	Run             _run.Data         `json:"run"`
	RunCounter      int               `json:"run_counter"`
	Runs            []_run.Data       `json:"runs"`
	Labels          map[string]string `json:"labels"`
}

Resp represent a task that can be send directly on the wire

type Task

type Task struct {
	Start           time.Time          `json:"start"`              // Start time
	MaxWaitTime     time.Duration      `json:"max_wait_time"`      // Max wait time before starting Action
	MaxExectionTime time.Duration      `json:"max_execution_time"` // Max execution time
	CPU             int                `json:"cpu"`                // CPU quota
	RAM             int                `json:"ram"`                // RAM quota
	Action          action.Action      `json:"action"`             // Action is an abstract, the thing to do
	Id              uuid.UUID          `json:"id"`                 // Id
	Cancel          context.CancelFunc `json:"-"`                  // Cancel the action
	Status          status.Status      `json:"status"`             // Status
	Mtime           time.Time          `json:"mtime"`              // Modified time
	Owner           string             `json:"owner"`              // Owner
	Retry           int                `json:"retry"`              // Number of retry before crash
	Every           time.Duration      `json:"every"`              // Periodic execution. Exclusive with Cron
	Cron            string             `json:"cron"`               // Cron definition. Exclusive with Every
	Environments    map[string]string  `json:"environments,omitempty"`

	Run        _run.Run          `json:"run"`
	RunCounter int               `json:"run_counter"`
	Runs       []_run.Data       `json:"runs"`
	Labels     map[string]string `json:"labels"`
	// contains filtered or unexported fields
}

Task something to do

func New

func New() *Task

func NewTask

func NewTask(o string, a action.Action) Task

NewTask init a new task

func (*Task) AddRunToHistory

func (t *Task) AddRunToHistory(r _run.Run)

AddRunToHistory adds run to history by prepending it

func (*Task) HasCron

func (t *Task) HasCron() bool

HasCron return true if tasks has a cron or an every planified

func (*Task) InjectPredefinedEnv

func (t *Task) InjectPredefinedEnv()

InjectPredefinedEnv is used to inject or modifiy Density predefined env variables

func (*Task) MarshalJSON

func (t *Task) MarshalJSON() ([]byte, error)

func (*Task) PrepareReschedule

func (t *Task) PrepareReschedule()

PrepareRechedule is used to modify start date in the future in case of a configured cron or every ! This does no check if cron or every is a valid value

func (*Task) ToTaskResp

func (t *Task) ToTaskResp() Resp

ToTaskResp will Convert a Task to TaskResp

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(b []byte) error

type TaskByKarma

type TaskByKarma []*Task

func (TaskByKarma) Len

func (t TaskByKarma) Len() int

func (TaskByKarma) Less

func (t TaskByKarma) Less(i, j int) bool

func (TaskByKarma) Swap

func (t TaskByKarma) Swap(i, j int)

type TaskByStart

type TaskByStart []*Task

func (TaskByStart) Len

func (t TaskByStart) Len() int

func (TaskByStart) Less

func (t TaskByStart) Less(i, j int) bool

func (TaskByStart) Swap

func (t TaskByStart) Swap(i, j int)

type Validator

type Validator struct {
	Validators map[string]map[string]interface{} `yaml:"validators"`
	// contains filtered or unexported fields
}

func (*Validator) Register

func (val *Validator) Register() error

func (*Validator) ValidateAction

func (v *Validator) ValidateAction(a Action) []error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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