Documentation ¶
Index ¶
- func DeleteOrMove(errorGroup string, tasks ...*Task) func(err error) MultiOp
- 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 (c *Client) CommitOrMove(ctx context.Context, task *masstasker.Task, err error, errorGroup string) errordeprecated
- func (c *Client) ComplexUpdate(ctx context.Context, create []*masstasker.Task, delete []*masstasker.Task, ...) errordeprecated
- func (c *Client) Create(ctx context.Context, tasks ...*masstasker.Task) errordeprecated
- func (c *Client) Delete(ctx context.Context, tasks ...*masstasker.Task) errordeprecated
- func (c *Client) Disown(ctx context.Context, tasks ...*masstasker.Task) errordeprecated
- func (c *Client) Do(ctx context.Context, ops ...MultiOp) error
- func (c *Client) Move(ctx context.Context, targetGroup string, tasks ...*masstasker.Task) errordeprecated
- 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) errordeprecated
- func (c *Client) RunWithLease(ctx context.Context, task *masstasker.Task, ...) error
- func (c *Client) Update(ctx context.Context, tasks ...*masstasker.Task) errordeprecated
- type LeaseOption
- type MultiOp
- type QueryOpt
- type SavedError
- type Task
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteOrMove ¶ added in v0.1.15
DeleteOrMove produces either a Move op or a Delete op, depending on whether the error is a saved error
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
deprecated
added in
v0.1.11
func (c *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.
Deprecated: Use Client.Do with DeleteOrMove
func (*Client) ComplexUpdate
deprecated
func (c *Client) ComplexUpdate(ctx context.Context, create []*masstasker.Task, delete []*masstasker.Task, predicates []*masstasker.Task) error
Deprecated: use Client.Do
func (*Client) Create
deprecated
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
deprecated
added in
v0.1.11
func (*Client) Do ¶ added in v0.1.15
Do performs a transactional update of the masstasker state by performing all the provided operations atomically.
func (*Client) Move
deprecated
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
deprecated
added in
v0.1.11
func (*Client) RunWithLease ¶ added in v0.1.11
func (c *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 MultiOp ¶ added in v0.1.15
func Create ¶ added in v0.1.15
The Create op will create new tasks when executed. The allocated IDs will be set in the provided task when the op is executed.
func Move ¶ added in v0.1.15
The Move operation is an Update where all the Group fields are updated to the provided value.
func Pred ¶ added in v0.1.15
The pred op records the IDs of the provided tasks and check that tasks with such IDs exist.
func Reown ¶ added in v0.1.15
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 Update ¶ added in v0.1.15
Update is an operation that combines a Delete with a Create of the same task.
Tasks are immutable and cannot be updated in place. By deleting the task and contextually re-create a new task with the updated content the ID changes and other workers can notice that the task has been updated.
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
Example (Data) ¶
package main import ( "fmt" "log" "mkm.pub/masstasker" mypb "mkm.pub/masstasker/pkg/proto" ) func main() { task, err := masstasker.NewTask("my_group", &mypb.Test{Foo: "bar"}) if err != nil { log.Fatal(err) } // ... var data mypb.Test if err := task.UnmarshalDataTo(&data); err != nil { log.Fatal(err) } fmt.Println(data.Foo) }
Output: bar