Documentation ¶
Index ¶
- func IsSavedError(err error) bool
- func NewSavedError(err error) error
- func NewTask(group string, data proto.Message) (*masstasker.Task, error)
- type Client
- func (c *Client) Close()
- func (mt *Client) CommitOrMove(ctx context.Context, task *masstasker.Task, err error, errorGroup string) error
- func (c *Client) ComplexUpdate(ctx context.Context, create []*masstasker.Task, delete []*masstasker.Task, ...) error
- func (c *Client) Create(ctx context.Context, tasks ...*masstasker.Task) error
- func (c *Client) Delete(ctx context.Context, tasks ...*masstasker.Task) error
- func (c *Client) Disown(ctx context.Context, tasks ...*masstasker.Task) error
- func (c *Client) Move(ctx context.Context, targetGroup string, tasks ...*masstasker.Task) error
- func (c *Client) Query(ctx context.Context, group string, ownFor time.Duration, opts ...QueryOpt) (*masstasker.Task, error)
- func (c *Client) Reown(ctx context.Context, ownFor time.Duration, tasks ...*masstasker.Task) error
- func (mt *Client) RunWithLease(ctx context.Context, task *masstasker.Task, ...) error
- func (c *Client) Update(ctx context.Context, tasks ...*masstasker.Task) error
- type LeaseOption
- type QueryOpt
- type SavedError
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSavedError ¶ added in v0.1.11
func NewSavedError ¶ added in v0.1.11
NewSavedError creates a SavedError
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 ¶
Dial connects to the gRPC service and returns a Client.
Common opts: grpc.WithTransportCredentials(insecure.NewCredentials())
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 ¶
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) Disown ¶ added in v0.1.11
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
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) Reown ¶ added in v0.1.11
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
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 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