service

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0, BSD-3-Clause, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Created is the initial task state.
	Created = "created"

	// Pending state is when a worker has marked the task for processing
	// indicating to other workers that they should not process the task.
	Pending = "pending"

	// Done state is when the task is completed.
	// TODO(penkovski): do we need this state if task is deleted after it is done?
	Done = "done"

	// Failed state is when the task execution failed but the task is part
	// of a group and later execution is not possible, so it could not be "Unack"-ed
	Failed = "failed"
)

Variables

This section is empty.

Functions

func NewErrorResponse

func NewErrorResponse(ctx context.Context, err error) goahttp.Statuser

Types

type EventTask

type EventTask struct {
	Key       string `json:"key"`
	Namespace string `json:"namespace"`
	Scope     string `json:"scope"`
	TaskName  string
}

type Group

type Group struct {
	ID          string   `json:"id"`
	Execution   string   `json:"execution"`
	Tasks       []string `json:"tasks"`
	State       State    `json:"state"`
	Request     []byte   `json:"request"`
	FinalPolicy string   `json:"finalPolicy"`
}

type GroupTemplate

type GroupTemplate struct {
	Execution   string   `json:"execution"`
	FinalPolicy string   `json:"finalPolicy"`
	Tasks       []string `json:"tasks"`
}

type Queue

type Queue interface {
	// Task related methods
	Add(ctx context.Context, task *Task) error
	Poll(ctx context.Context) (*Task, error)
	Ack(ctx context.Context, task *Task) error
	Unack(ctx context.Context, task *Task) error

	// TaskList related methods
	AddTaskList(ctx context.Context, taskList *TaskList, tasks []*Task) error
	PollList(ctx context.Context) (*TaskList, error)
	AckList(ctx context.Context, taskList *TaskList) error
	AckGroupTasks(ctx context.Context, group *Group) error
}

type State

type State string

type Storage

type Storage interface {
	// Task related methods
	Task(ctx context.Context, taskID string) (*Task, error)
	TaskTemplate(ctx context.Context, taskName string) (*Task, error)
	TaskHistory(ctx context.Context, taskID string) (*Task, error)
	SaveTaskHistory(ctx context.Context, task *Task) error

	// TaskList related methods
	TaskList(ctx context.Context, taskListID string) (*TaskList, error)
	TaskListTemplate(ctx context.Context, taskListName string) (*Template, error)
	TaskTemplates(ctx context.Context, names []string) (map[string]*Task, error)
	TaskListHistory(ctx context.Context, taskListID string) (*TaskList, error)
	GetGroupTasks(ctx context.Context, group *Group) ([]*Task, error)
	SaveTaskListHistory(ctx context.Context, task *TaskList) error

	// EventTask related methods
	EventTask(ctx context.Context, key, namespace, scope string) (*EventTask, error)
}

type Task

type Task struct {
	ID             string    `json:"id"`             // ID is unique task identifier.
	GroupID        string    `json:"groupID"`        // GroupID is set when the task is part of `tasklist.Group`.
	Name           string    `json:"name"`           // Name is used by external callers use to create tasks.
	State          State     `json:"state"`          // State of the task.
	URL            string    `json:"url"`            // URL against which the task request will be executed (optional).
	Method         string    `json:"method"`         // HTTP method of the task request (optional).
	Request        []byte    `json:"request"`        // Request body which will be sent in the task request.
	Response       []byte    `json:"response"`       // Response received after the task request is executed.
	ResponseCode   int       `json:"responseCode"`   // ResponseCode received after task request is executed.
	RequestPolicy  string    `json:"requestPolicy"`  // RequestPolicy to be executed before task request execution.
	ResponsePolicy string    `json:"responsePolicy"` // ResponsePolicy to be executed on the task response.
	FinalPolicy    string    `json:"finalPolicy"`    // FinalPolicy to be executed on the task response.
	CacheNamespace string    `json:"cacheNamespace"` // CacheNamespace if set, is used for constructing cache key.
	CacheScope     string    `json:"cacheScope"`     // CacheScope if set, is used for constructing cache key.
	Retries        int       `json:"retries"`        // Retries is the number of failed attempts to execute this task
	CreatedAt      time.Time `json:"createdAt"`      // CreatedAt specifies task creation time.
	StartedAt      time.Time `json:"startedAt"`      // StartedAt specifies task execution start time.
	FinishedAt     time.Time `json:"finishedAt"`     // FinishedAt specifies the time when the task is done.
}

func (*Task) CacheKey

func (t *Task) CacheKey() string

CacheKey constructs the key for storing task result in the cache.

type TaskList

type TaskList struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	State          State     `json:"state"`
	Groups         []Group   `json:"groups"`
	Request        []byte    `json:"request"`
	CacheNamespace string    `json:"cacheNamespace"`
	CacheScope     string    `json:"cacheScope"`
	CreatedAt      time.Time `json:"createdAt"`
	StartedAt      time.Time `json:"startedAt"`
	FinishedAt     time.Time `json:"finishedAt"`
}

type Template

type Template struct {
	Name           string          `json:"name"`
	CacheNamespace string          `json:"cacheNamespace"`
	CacheScope     string          `json:"cacheScope"`
	Groups         []GroupTemplate `json:"groups"`
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
taskfakes
Code generated by counterfeiter.
Code generated by counterfeiter.
tasklistfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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