task

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	State_name = map[int32]string{
		0: "STATE_UNKNOWN",
		1: "RUNNING",
		2: "SUCCESS",
		3: "FAILURE",
	}
	State_value = map[string]int32{
		"STATE_UNKNOWN": 0,
		"RUNNING":       1,
		"SUCCESS":       2,
		"FAILURE":       3,
	}
)

Enum value maps for State.

View Source
var File_internal_task_task_proto protoreflect.FileDescriptor

Functions

func Count

func Count(ctx context.Context, service Service, namespace, group string) (tasks int64, claims int64, retErr error)

Count returns the number of tasks and claims in the given namespace and group (if nonempty)

func DoBatch

func DoBatch(ctx context.Context, doer Doer, inputs []*anypb.Any, cb CollectFunc) error

DoBatch executes a batch of tasks.

func DoOne

func DoOne(ctx context.Context, doer Doer, input *anypb.Any) (*anypb.Any, error)

DoOne executes one task. NOTE: This interface is much less performant than the stream / batch interfaces for many tasks. Only use this interface for development / a small number of tasks.

func DoOrdered

func DoOrdered(ctx context.Context, doer Doer, inputs chan *anypb.Any, parallelism int, cb CollectFunc) error

DoOrdered processes tasks in parallel, but returns outputs in order via the provided callback cb.

func List

func List(ctx context.Context, svc Service, req *taskapi.ListTaskRequest, send func(info *taskapi.TaskInfo) error) error

List implements the functionality for an arbitrary service's ListTask gRPC

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (output *anypb.Any, _ error)
	Put(ctx context.Context, key string, output *anypb.Any) error
}

type Claim

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

func (*Claim) Descriptor deprecated

func (*Claim) Descriptor() ([]byte, []int)

Deprecated: Use Claim.ProtoReflect.Descriptor instead.

func (*Claim) MarshalLogObject

func (x *Claim) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Claim) ProtoMessage

func (*Claim) ProtoMessage()

func (*Claim) ProtoReflect added in v2.7.0

func (x *Claim) ProtoReflect() protoreflect.Message

func (*Claim) Reset

func (x *Claim) Reset()

func (*Claim) String

func (x *Claim) String() string

func (*Claim) Validate added in v2.8.0

func (m *Claim) Validate() error

Validate checks the field values on Claim with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*Claim) ValidateAll added in v2.8.0

func (m *Claim) ValidateAll() error

ValidateAll checks the field values on Claim with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in ClaimMultiError, or nil if none found.

type ClaimMultiError added in v2.8.0

type ClaimMultiError []error

ClaimMultiError is an error wrapping multiple validation errors returned by Claim.ValidateAll() if the designated constraints aren't met.

func (ClaimMultiError) AllErrors added in v2.8.0

func (m ClaimMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (ClaimMultiError) Error added in v2.8.0

func (m ClaimMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type ClaimValidationError added in v2.8.0

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

ClaimValidationError is the validation error returned by Claim.Validate if the designated constraints aren't met.

func (ClaimValidationError) Cause added in v2.8.0

func (e ClaimValidationError) Cause() error

Cause function returns cause value.

func (ClaimValidationError) Error added in v2.8.0

func (e ClaimValidationError) Error() string

Error satisfies the builtin error interface

func (ClaimValidationError) ErrorName added in v2.8.0

func (e ClaimValidationError) ErrorName() string

ErrorName returns error name.

func (ClaimValidationError) Field added in v2.8.0

func (e ClaimValidationError) Field() string

Field function returns field value.

func (ClaimValidationError) Key added in v2.8.0

func (e ClaimValidationError) Key() bool

Key function returns key value.

func (ClaimValidationError) Reason added in v2.8.0

func (e ClaimValidationError) Reason() string

Reason function returns reason value.

type CollectFunc

type CollectFunc = func(index int64, output *anypb.Any, _ error) error

CollectFunc is the type of a function that is used for collecting the output of a stream / batch of tasks. Index is the index of a task with respect to the order in which the task was created in the stream / batch.

type Doer

type Doer interface {
	// Do creates and returns the results of processing a stream of tasks provided
	// by the input channel. The client should close the input channel when all tasks have
	// been sent (it does not need to be closed if the context is canceled). For each
	// task, the collect function will be called with the results.
	Do(ctx context.Context, inputChan chan *anypb.Any, cb CollectFunc) error
}

Doer is a doer of tasks. Refer to the DoOne and DoBatch helper functions if a simpler interface is desired.

type Group

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

func (*Group) Descriptor deprecated

func (*Group) Descriptor() ([]byte, []int)

Deprecated: Use Group.ProtoReflect.Descriptor instead.

func (*Group) MarshalLogObject

func (x *Group) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Group) ProtoMessage

func (*Group) ProtoMessage()

func (*Group) ProtoReflect added in v2.7.0

func (x *Group) ProtoReflect() protoreflect.Message

func (*Group) Reset

func (x *Group) Reset()

func (*Group) String

func (x *Group) String() string

func (*Group) Validate added in v2.8.0

func (m *Group) Validate() error

Validate checks the field values on Group with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*Group) ValidateAll added in v2.8.0

func (m *Group) ValidateAll() error

ValidateAll checks the field values on Group with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in GroupMultiError, or nil if none found.

type GroupMultiError added in v2.8.0

type GroupMultiError []error

GroupMultiError is an error wrapping multiple validation errors returned by Group.ValidateAll() if the designated constraints aren't met.

func (GroupMultiError) AllErrors added in v2.8.0

func (m GroupMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (GroupMultiError) Error added in v2.8.0

func (m GroupMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type GroupValidationError added in v2.8.0

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

GroupValidationError is the validation error returned by Group.Validate if the designated constraints aren't met.

func (GroupValidationError) Cause added in v2.8.0

func (e GroupValidationError) Cause() error

Cause function returns cause value.

func (GroupValidationError) Error added in v2.8.0

func (e GroupValidationError) Error() string

Error satisfies the builtin error interface

func (GroupValidationError) ErrorName added in v2.8.0

func (e GroupValidationError) ErrorName() string

ErrorName returns error name.

func (GroupValidationError) Field added in v2.8.0

func (e GroupValidationError) Field() string

Field function returns field value.

func (GroupValidationError) Key added in v2.8.0

func (e GroupValidationError) Key() bool

Key function returns key value.

func (GroupValidationError) Reason added in v2.8.0

func (e GroupValidationError) Reason() string

Reason function returns reason value.

type ProcessFunc

type ProcessFunc = func(ctx context.Context, input *anypb.Any) (output *anypb.Any, _ error)

ProcessFunc is the type of a function that is use for processing a task. If an error occurs, then it should be returned. This error will be propagated back to the Doer that created the task.

type Service

type Service interface {
	// NewDoer creates a Doer with the provided namespace and group.
	NewDoer(namespace, group string, cache Cache) Doer
	// NewSource creates a Source with the provided namespace.
	NewSource(namespace string) Source
	// List calls a function on every task under a namespace and group
	List(ctx context.Context, namespace, group string, cb func(namespace, group string, data *Task, claimed bool) error) error
	// Count returns the number of tasks under a namespace.
	Count(ctx context.Context, namespace string) (int64, error)
}

Scheduling: A task managed by a Service has a group. The group is used for scheduling purposes. Scheduling is based on maximizing fairness for the groups, and the schedulable unit is a task.

func NewEtcdService

func NewEtcdService(etcdClient *etcd.Client, etcdPrefix string) Service

type Source

type Source interface {
	// Iterate iterates through tasks until the provided context is canceled.
	// For each task, the process function will be called and the results
	// will be returned to the Doer that created the task.
	Iterate(ctx context.Context, cb ProcessFunc) error
}

Source is a source of tasks.

type State

type State int32
const (
	State_STATE_UNKNOWN State = 0
	State_RUNNING       State = 1
	State_SUCCESS       State = 2
	State_FAILURE       State = 3
)

func (State) Descriptor added in v2.7.0

func (State) Descriptor() protoreflect.EnumDescriptor

func (State) Enum added in v2.7.0

func (x State) Enum() *State

func (State) EnumDescriptor deprecated

func (State) EnumDescriptor() ([]byte, []int)

Deprecated: Use State.Descriptor instead.

func (State) Number added in v2.7.0

func (x State) Number() protoreflect.EnumNumber

func (State) String

func (x State) String() string

func (State) Type added in v2.7.0

func (State) Type() protoreflect.EnumType

type Task

type Task struct {
	Id     string     `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	State  State      `protobuf:"varint,2,opt,name=state,proto3,enum=task.State" json:"state,omitempty"`
	Input  *anypb.Any `protobuf:"bytes,3,opt,name=input,proto3" json:"input,omitempty"`
	Output *anypb.Any `protobuf:"bytes,4,opt,name=output,proto3" json:"output,omitempty"`
	Reason string     `protobuf:"bytes,5,opt,name=reason,proto3" json:"reason,omitempty"`
	Index  int64      `protobuf:"varint,6,opt,name=index,proto3" json:"index,omitempty"`
	// contains filtered or unexported fields
}

TODO: Consider splitting this up into separate structures for each state in a oneof.

func (*Task) Descriptor deprecated

func (*Task) Descriptor() ([]byte, []int)

Deprecated: Use Task.ProtoReflect.Descriptor instead.

func (*Task) GetId added in v2.7.0

func (x *Task) GetId() string

func (*Task) GetIndex

func (x *Task) GetIndex() int64

func (*Task) GetInput

func (x *Task) GetInput() *anypb.Any

func (*Task) GetOutput

func (x *Task) GetOutput() *anypb.Any

func (*Task) GetReason

func (x *Task) GetReason() string

func (*Task) GetState

func (x *Task) GetState() State

func (*Task) MarshalLogObject

func (x *Task) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Task) ProtoMessage

func (*Task) ProtoMessage()

func (*Task) ProtoReflect added in v2.7.0

func (x *Task) ProtoReflect() protoreflect.Message

func (*Task) Reset

func (x *Task) Reset()

func (*Task) String

func (x *Task) String() string

func (*Task) Validate added in v2.8.0

func (m *Task) Validate() error

Validate checks the field values on Task with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*Task) ValidateAll added in v2.8.0

func (m *Task) ValidateAll() error

ValidateAll checks the field values on Task with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in TaskMultiError, or nil if none found.

type TaskMultiError added in v2.8.0

type TaskMultiError []error

TaskMultiError is an error wrapping multiple validation errors returned by Task.ValidateAll() if the designated constraints aren't met.

func (TaskMultiError) AllErrors added in v2.8.0

func (m TaskMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (TaskMultiError) Error added in v2.8.0

func (m TaskMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type TaskValidationError added in v2.8.0

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

TaskValidationError is the validation error returned by Task.Validate if the designated constraints aren't met.

func (TaskValidationError) Cause added in v2.8.0

func (e TaskValidationError) Cause() error

Cause function returns cause value.

func (TaskValidationError) Error added in v2.8.0

func (e TaskValidationError) Error() string

Error satisfies the builtin error interface

func (TaskValidationError) ErrorName added in v2.8.0

func (e TaskValidationError) ErrorName() string

ErrorName returns error name.

func (TaskValidationError) Field added in v2.8.0

func (e TaskValidationError) Field() string

Field function returns field value.

func (TaskValidationError) Key added in v2.8.0

func (e TaskValidationError) Key() bool

Key function returns key value.

func (TaskValidationError) Reason added in v2.8.0

func (e TaskValidationError) Reason() string

Reason function returns reason value.

type TestTask

type TestTask struct {
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

func (*TestTask) Descriptor deprecated

func (*TestTask) Descriptor() ([]byte, []int)

Deprecated: Use TestTask.ProtoReflect.Descriptor instead.

func (*TestTask) GetId added in v2.7.0

func (x *TestTask) GetId() string

func (*TestTask) MarshalLogObject

func (x *TestTask) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*TestTask) ProtoMessage

func (*TestTask) ProtoMessage()

func (*TestTask) ProtoReflect added in v2.7.0

func (x *TestTask) ProtoReflect() protoreflect.Message

func (*TestTask) Reset

func (x *TestTask) Reset()

func (*TestTask) String

func (x *TestTask) String() string

func (*TestTask) Validate added in v2.8.0

func (m *TestTask) Validate() error

Validate checks the field values on TestTask with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*TestTask) ValidateAll added in v2.8.0

func (m *TestTask) ValidateAll() error

ValidateAll checks the field values on TestTask with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in TestTaskMultiError, or nil if none found.

type TestTaskMultiError added in v2.8.0

type TestTaskMultiError []error

TestTaskMultiError is an error wrapping multiple validation errors returned by TestTask.ValidateAll() if the designated constraints aren't met.

func (TestTaskMultiError) AllErrors added in v2.8.0

func (m TestTaskMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (TestTaskMultiError) Error added in v2.8.0

func (m TestTaskMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type TestTaskValidationError added in v2.8.0

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

TestTaskValidationError is the validation error returned by TestTask.Validate if the designated constraints aren't met.

func (TestTaskValidationError) Cause added in v2.8.0

func (e TestTaskValidationError) Cause() error

Cause function returns cause value.

func (TestTaskValidationError) Error added in v2.8.0

func (e TestTaskValidationError) Error() string

Error satisfies the builtin error interface

func (TestTaskValidationError) ErrorName added in v2.8.0

func (e TestTaskValidationError) ErrorName() string

ErrorName returns error name.

func (TestTaskValidationError) Field added in v2.8.0

func (e TestTaskValidationError) Field() string

Field function returns field value.

func (TestTaskValidationError) Key added in v2.8.0

func (e TestTaskValidationError) Key() bool

Key function returns key value.

func (TestTaskValidationError) Reason added in v2.8.0

func (e TestTaskValidationError) Reason() string

Reason function returns reason value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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