task

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateRunning   = "RUNNING"
	StateDone      = "DONE"
	StateTODO      = "TODO"    // default on creation
	StateBlocked   = "BLOCKED" // not automatically retriable, 400 bad requests, etc..
	StateCancelled = "CANCELLED"
	StateWontfix   = "WONTFIX"
)

possible task states

Variables

This section is empty.

Functions

func LoadStateCount

func LoadStateCount(dbp zesty.DBProvider, tags map[string]string) (sc map[string]float64, err error)

LoadStateCount returns a map containing the count of tasks grouped by state

func RegisterTaskTime added in v1.10.0

func RegisterTaskTime(templateName string, taskCreation, resCreation time.Time)

RegisterTaskTime computes the execution duration and the complete duration (from creation to completion) of a task. These metrics are then pushed to Prometheus.

func RegisterValidationTime added in v1.10.0

func RegisterValidationTime(templateName string, taskCreation time.Time)

RegisterValidationTime computes the duration between the task creation and the associated resolution's creation. This metric is then pushed to Prometheus.

func RotateTasks

func RotateTasks(dbp zesty.DBProvider) (err error)

RotateTasks loads all tasks stored in DB and makes sure that their cyphered content has been handled with the latest available storage key

Types

type Batch

type Batch struct {
	BatchDBModel
}

Batch represents a group of tasks, created under a common identifier

func CreateBatch

func CreateBatch(dbp zesty.DBProvider) (b *Batch, err error)

CreateBatch inserts a new batch in DB

func LoadBatchFromPublicID

func LoadBatchFromPublicID(dbp zesty.DBProvider, publicID string) (b *Batch, err error)

LoadBatchFromPublicID returns a task batch, loaded from DB given its ID

func (*Batch) Delete

func (b *Batch) Delete(dbp zesty.DBProvider) (err error)

Delete removes a task batch from DB

type BatchDBModel

type BatchDBModel struct {
	ID       int64  `json:"-" db:"id"`
	PublicID string `json:"id" db:"public_id"`
}

BatchDBModel is a Batch's representation in DB

type Comment

type Comment struct {
	ID       int64     `json:"-" db:"id"`
	PublicID string    `json:"id" db:"public_id"`
	TaskID   int64     `json:"-" db:"id_task"`
	Username string    `json:"username" db:"username"`
	Created  time.Time `json:"created" db:"created"`
	Updated  time.Time `json:"updated" db:"updated"`
	Content  string    `json:"content" db:"content"`
}

Comment is the structure representing a comment made on a task

func CreateComment

func CreateComment(dbp zesty.DBProvider, t *Task, user, content string) (c *Comment, err error)

CreateComment inserts a new comment in DB

func LoadCommentFromPublicID

func LoadCommentFromPublicID(dbp zesty.DBProvider, publicID string) (c *Comment, err error)

LoadCommentFromPublicID returns a single comment, given its ID

func LoadCommentsFromTaskID

func LoadCommentsFromTaskID(dbp zesty.DBProvider, taskID int64) (c []*Comment, err error)

LoadCommentsFromTaskID returns the list of comments related to a task

func (*Comment) Delete

func (c *Comment) Delete(dbp zesty.DBProvider) (err error)

Delete removes a comment from DB

func (*Comment) Update

func (c *Comment) Update(dbp zesty.DBProvider, content string) (err error)

Update changes the content of a comment in DB

func (*Comment) Valid

func (c *Comment) Valid() error

Valid asserts that the content of a message is whithin min/max character bounds

type DBModel

type DBModel struct {
	ID                int64             `json:"-" db:"id"`
	PublicID          string            `json:"id" db:"public_id"`
	Title             string            `json:"title" db:"title"`
	TemplateID        int64             `json:"-" db:"id_template"`
	BatchID           *int64            `json:"-" db:"id_batch"`
	RequesterUsername string            `json:"requester_username" db:"requester_username"`
	WatcherUsernames  []string          `json:"watcher_usernames,omitempty" db:"watcher_usernames"`
	ResolverUsernames []string          `json:"resolver_usernames,omitempty" db:"resolver_usernames"`
	Created           time.Time         `json:"created" db:"created"`
	State             string            `json:"state" db:"state"`
	StepsDone         int               `json:"steps_done" db:"steps_done"`
	StepsTotal        int               `json:"steps_total" db:"steps_total"`
	LastActivity      time.Time         `json:"last_activity" db:"last_activity"`
	Tags              map[string]string `json:"tags,omitempty" db:"tags"`

	CryptKey        []byte `json:"-" db:"crypt_key"` // key for encrypting steps (itself encrypted with master key)
	EncryptedInput  []byte `json:"-" db:"encrypted_input"`
	EncryptedResult []byte `json:"-" db:"encrypted_result"` // encrypted Result
}

DBModel is the "strict" representation of a task in DB, as expressed in SQL schema

type ListFilter

type ListFilter struct {
	RequesterUser                    *string
	PotentialResolverUser            *string
	RequesterOrPotentialResolverUser *string
	Last                             *string
	State                            *string
	Batch                            *Batch
	PageSize                         uint64
	Before                           *time.Time
	After                            *time.Time
	Tags                             map[string]string
	Template                         *string
}

ListFilter holds parameters for filtering a list of tasks

type StepError

type StepError struct {
	Step  string `json:"step"`
	Error string `json:"error"`
}

StepError holds an error and the name of the step from where it originated

type Task

type Task struct {
	DBModel
	TemplateName     string                 `json:"template_name" db:"template_name"`
	Input            map[string]interface{} `json:"input" db:"-"`
	Result           map[string]interface{} `json:"result,omitempty" db:"-"`
	ResultStr        string                 `json:"-" db:"-"`
	Resolution       *string                `json:"resolution,omitempty" db:"resolution_public_id"`
	LastStart        *time.Time             `json:"last_start,omitempty" db:"last_start"`
	LastStop         *time.Time             `json:"last_stop,omitempty" db:"last_stop"`
	ResolverUsername *string                `json:"resolver_username,omitempty" db:"resolver_username"`
	Comments         []*Comment             `json:"comments,omitempty" db:"-"`
	Batch            *string                `json:"batch,omitempty" db:"batch_public_id"`
	Errors           []StepError            `json:"errors,omitempty" db:"-"`
	ResolverInputs   []input.Input          `json:"resolver_inputs,omitempty" db:"resolver_inputs"`
}

Task is the full representation of a requested process on µTask A task is necessarily derived from a template, the formal description of the process to be executed, plus inputs provided by the requester The execution of the task will be handled through another structure, its resolution When the resolution is finalized, results will be committed back to the Task structure Comments can be added to a task, by all parties involved (requester and resolver) A task can be made visible to third parties by adding their usernames to the watcher_usernames list

func Create

func Create(dbp zesty.DBProvider, tt *tasktemplate.TaskTemplate, reqUsername string, watcherUsernames []string, resolverUsernames []string, input map[string]interface{}, tags map[string]string, b *Batch) (t *Task, err error)

Create inserts a new Task in DB

func ListTasks

func ListTasks(dbp zesty.DBProvider, filter ListFilter) (t []*Task, err error)

ListTasks returns a list of tasks, optionally filtered on one or several criteria

func LoadFromID

func LoadFromID(dbp zesty.DBProvider, ID int64) (t *Task, err error)

LoadFromID returns a single task, given its "private" ID only used internally, this ID is not exposed through µTask's API

func LoadFromPublicID

func LoadFromPublicID(dbp zesty.DBProvider, publicID string) (t *Task, err error)

LoadFromPublicID returns a single task, given its public ID

func LoadLockedFromPublicID

func LoadLockedFromPublicID(dbp zesty.DBProvider, publicID string) (t *Task, err error)

LoadLockedFromPublicID returns a single task, given its ID, locked for an update transaction, so that only one instance of µTask can make a claim on it and avoid collisions with other instances

func (*Task) Delete

func (t *Task) Delete(dbp zesty.DBProvider) (err error)

Delete removes a task from DB

func (*Task) ExportTaskInfos

func (t *Task) ExportTaskInfos(values *values.Values)

ExportTaskInfos records task-specific data to a Values structure

func (*Task) NotifyStepState added in v1.13.0

func (t *Task) NotifyStepState(stepName, stepState string)

func (*Task) NotifyValidationRequired added in v1.13.0

func (t *Task) NotifyValidationRequired(tt *tasktemplate.TaskTemplate)

func (*Task) SetInput

func (t *Task) SetInput(input map[string]interface{})

SetInput sets the provided input for the task

func (*Task) SetResult

func (t *Task) SetResult(values *values.Values) error

SetResult consolidates values collected during resolution into the task's final result

func (*Task) SetState

func (t *Task) SetState(s string)

SetState updates the task's state

func (*Task) SetTags added in v1.5.0

func (t *Task) SetTags(tags map[string]string, values *values.Values) error

func (*Task) SetWatcherUsernames

func (t *Task) SetWatcherUsernames(watcherUsernames []string)

SetWatcherUsernames sets the list of watchers for the task

func (*Task) Update

func (t *Task) Update(dbp zesty.DBProvider, skipValidation, recordLastActivity bool) (err error)

Update commits changes to a task's state to DB A flag allows to skip validation: only exposed internally for special situations, where a task could be out of sync with its template

func (*Task) Valid

func (t *Task) Valid(tt *tasktemplate.TaskTemplate) error

Valid asserts that the task holds valid data: the state is among accepted states, and input is present and valid given the template spec

Jump to

Keyboard shortcuts

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