masstasker

package module
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSavedError added in v0.1.11

func IsSavedError(err error) bool

func NewSavedError added in v0.1.11

func NewSavedError(err error) error

NewSavedError creates a SavedError

func NewTask added in v0.1.9

func NewTask(group string, data proto.Message) (*masstasker.Task, error)

NewTask is sugar for creating a Task in a given group and the given proto into the Data field.

Types

type Client

type Client struct {
	RPC masstasker.MassTaskerClient
	// contains filtered or unexported fields
}

A Client is a high-level client to the MassTasker API.

It operates directly on masstasker.Task protobuf messages. The main advantage of using this high-level API over the low-level gRPC one is that all Client's method operate on Task structures and you rarely have to care about IDs.

Tasks in MassTasker server are immutable. You can't update a task. What you do is you delete a task and atomically create a new one. This high-level API lets you express this by simply mutating the in-memory client task and issuing an update request. After the call, the task will have the new ID.

func Connect

func Connect(conn *grpc.ClientConn) *Client

Connect creates a connection from an underlying grpc client connection.

func Dial

func Dial(ctx context.Context, addr string, opts ...grpc.DialOption) (*Client, error)

Dial connects to the gRPC service and returns a Client.

Common opts: grpc.WithTransportCredentials(insecure.NewCredentials())

func (*Client) Close

func (c *Client) Close()

func (*Client) CommitOrMove added in v0.1.11

func (mt *Client) CommitOrMove(ctx context.Context, task *masstasker.Task, err error, errorGroup string) error

CommitOrMove deletes the task if err is nil, or moves the task to an errorGroup if the error is a "saved error". Otherwise it "disowns" the task so that another worker can pick it up as soon as they are not busy with older tasks. Any other error that is not a "saved error" is returned by this function after the task is "disowned" If errorGroup is empty, then it doesn't move saved errors to the error group but simply returns them as any other error.

func (*Client) ComplexUpdate

func (c *Client) ComplexUpdate(ctx context.Context, create []*masstasker.Task, delete []*masstasker.Task, predicates []*masstasker.Task) error

func (*Client) Create

func (c *Client) Create(ctx context.Context, tasks ...*masstasker.Task) error

Create creates the given tasks. The IDs are allocated upon task creation and are not known until the server responds. This method updates the task IDs in the arguments with the IDs returned by the server.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, tasks ...*masstasker.Task) error

func (*Client) Disown added in v0.1.11

func (c *Client) Disown(ctx context.Context, tasks ...*masstasker.Task) error

Disown is just a "sugar" for a) reset the NotBefore field in every task b) issue an Update Sometimes it makes the intent of the client code clearer.

func (*Client) Move added in v0.1.7

func (c *Client) Move(ctx context.Context, targetGroup string, tasks ...*masstasker.Task) error

Move is just a "sugar" for a) update the Group field in every task b) issue an Update to to move the task to another group. Sometimes it makes the intent of the client code clearer.

func (*Client) Query

func (c *Client) Query(ctx context.Context, group string, ownFor time.Duration, opts ...QueryOpt) (*masstasker.Task, error)

func (*Client) Reown added in v0.1.11

func (c *Client) Reown(ctx context.Context, ownFor time.Duration, tasks ...*masstasker.Task) error

Reown is just a "sugar" for a) set the NotBefore field in every task by now+ownFor b) issue an Update Sometimes it makes the intent of the client code clearer.

func (*Client) RunWithLease added in v0.1.11

func (mt *Client) RunWithLease(ctx context.Context, task *masstasker.Task, fn func(context.Context, *masstasker.Task) error, opts ...LeaseOption) error

RunWithLease runs fn while in the background "renewing a lease" on the task by periodically updating bumping the NotBefore

func (*Client) Update

func (c *Client) Update(ctx context.Context, tasks ...*masstasker.Task) error

type LeaseOption added in v0.1.11

type LeaseOption func(*leaseOptions)

func WithHeartbeat added in v0.1.11

func WithHeartbeat(d time.Duration) LeaseOption

func WithOwnFor added in v0.1.11

func WithOwnFor(d time.Duration) LeaseOption

type QueryOpt

type QueryOpt func(*masstasker.QueryRequest)

func NonBlocking

func NonBlocking(v bool) QueryOpt

type SavedError added in v0.1.11

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

A SavedError wraps an error and can be used to signal that an error is not meant to be retried indefinitely but instead the task should be moved to an error group.

func (SavedError) Error added in v0.1.11

func (r SavedError) Error() string

func (SavedError) Unwrap added in v0.1.11

func (r SavedError) Unwrap() error

type Task

type Task = masstasker.Task

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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