task

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueEmpty = errors.New("queue empty")
	ErrQueueFull  = errors.New("queue full")
)
View Source
var (
	ErrNotFound = errors.New("task not found")
)

Functions

This section is empty.

Types

type CreatedBy added in v0.6.0

type CreatedBy struct {
	User   string `json:"user,omitempty"`
	Repo   string `json:"repo,omitempty"`
	Branch string `json:"branch,omitempty"`
	Commit string `json:"commit,omitempty"`
}

type DatedState added in v0.6.0

type DatedState struct {
	Created time.Time `json:"created"`
	State   State     `json:"state"`
}

DatedState (kind: struct) is a State with a timestamp.

type Outcome added in v0.6.0

type Outcome string
const (
	OutcomeUnknown  Outcome = "unknown"
	OutcomeSuccess  Outcome = "success"
	OutcomeFailure  Outcome = "failure"
	OutcomeCanceled Outcome = "canceled"
)

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue is a priority queue for tasks.

func NewQueue

func NewQueue(ts *Storage, max int, converter func([]byte) (*Task, error)) (*Queue, error)

func (*Queue) Pop

func (q *Queue) Pop() (*Task, error)

get the next item from the priority queue Pop the task off of the queue The task remains in the database, but is no longer in the heap. As the state of the task changes

func (*Queue) Push

func (q *Queue) Push(tsk *Task) error

Add an item to the priority queue 1. Check if we have too many items enqueued already. 2. Persist task to the database. 3. Push the task into the in-memory heap.

func (*Queue) PushUniqueByBranch added in v0.6.0

func (q *Queue) PushUniqueByBranch(tsk *Task) error

Pushes a task to the queue, and removes any tasks with matching repo/branch from the queue

type State added in v0.6.0

type State string

State (kind: string) represents the last known state of a task. A task can be in one of three states StateScheduled: this is the initial state of the task when it enters the queue. StateProcessing: once work begins on the task, it is put into this state. StateComplete: work is no longer being done on this task. client should check task result.

const (
	StateScheduled  State = "scheduled"
	StateProcessing State = "processing"
	StateComplete   State = "complete"
	StateCanceled   State = "canceled"
)

type Storage added in v0.6.0

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

Tasks stored in leveldb

func NewMemoryTaskStorage added in v0.6.0

func NewMemoryTaskStorage() (*Storage, error)

func NewTaskStorage added in v0.6.0

func NewTaskStorage(path string) (*Storage, error)

func (*Storage) ArchiveTask added in v0.6.0

func (s *Storage) ArchiveTask(tsk *Task) error

func (*Storage) Delete added in v0.6.0

func (s *Storage) Delete(id string) error

func (*Storage) Filter added in v0.6.0

func (s *Storage) Filter(state State, start time.Time, end time.Time) (tasks []*Task, err error)

func (*Storage) Get added in v0.6.0

func (s *Storage) Get(id string) (*Task, error)

func (*Storage) PersistProcessing added in v0.6.0

func (s *Storage) PersistProcessing(tsk *Task) error

func (*Storage) PersistScheduled added in v0.6.0

func (s *Storage) PersistScheduled(tsk *Task) error

func (*Storage) ProcessTask added in v0.6.0

func (s *Storage) ProcessTask(tsk *Task) error

type Task

type Task struct {
	Version     int          `json:"version"`     // Schema version
	Priority    int          `json:"priority"`    // Scheduling priority
	ID          string       `json:"id"`          // Unique identifier for this task
	Runner      string       `json:"runner"`      // Runner that ran this task
	Plan        string       `json:"plan"`        // Test plan
	Case        string       `json:"case"`        // Test case
	States      []DatedState `json:"states"`      // State of the task
	Type        Type         `json:"type"`        // Type of the task
	Composition interface{}  `json:"composition"` // Composition used for the task
	Input       interface{}  `json:"input"`       // The input data for this task
	Result      interface{}  `json:"result"`      // Result of the task, when terminal.
	Error       string       `json:"error"`       // Error from Testground
	CreatedBy   CreatedBy    `json:"created_by"`  // Who created the task
}

Task (kind: struct) contains metadata about a testground task. This schema is used to store metadata in our task storage database as well as the wire format returned when clients get the state of a running or scheduled task.

func (*Task) Created

func (t *Task) Created() time.Time

func (*Task) CreatedByCI added in v0.6.0

func (t *Task) CreatedByCI() bool

func (*Task) IsCanceled added in v0.6.0

func (t *Task) IsCanceled() bool

func (*Task) Name added in v0.6.0

func (t *Task) Name() string

func (*Task) RenderCreatedBy added in v0.6.0

func (t *Task) RenderCreatedBy() string

func (*Task) State added in v0.6.0

func (t *Task) State() DatedState

func (*Task) Took added in v0.6.0

func (t *Task) Took() time.Duration

type Type added in v0.6.0

type Type string

Type (kind: string) represents the kind of activity the daemon asked to perform. In alignment with the testground command-line we have two kinds of tasks TypeBuild -- which functions similarly to `testground build`. The result of this task will contain a build ID which can be used in a subsequent run. TypeRun -- which functions similarly to `testground run`

const (
	TypeBuild Type = "build"
	TypeRun   Type = "run"
)

Jump to

Keyboard shortcuts

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