Documentation
¶
Index ¶
- Variables
- type Client
- type ClientOptions
- type Handle
- func (h *Handle) Discard() error
- func (h *Handle) Done(ctx context.Context, meta map[string]string) error
- func (h *Handle) ID() uuid.UUID
- func (h *Handle) Metadata() map[string]string
- func (h *Handle) Renew(ctx context.Context, meta map[string]string) error
- func (h *Handle) SetMeta(key, value string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrAcquired error is returned if the resource is already acquired. ErrAcquired = errors.New("accord: acquired") // ErrDone error is returned if the resource is already marked done. ErrDone = errors.New("accord: done") // ErrClosed error is returned by the handle if closed. ErrClosed = errors.New("accord: closed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a convenience client to the accord API.
Example ¶
package main
import (
"context"
"fmt"
"github.com/bsm/accord"
)
func main() {
ctx := context.Background()
// Create a new client
client, err := accord.DialClient(ctx, "10.0.0.1:8432", &accord.ClientOptions{
Namespace: "/custom/namespace",
})
if err != nil {
panic(err)
}
defer client.Close()
// Acquire resource handle.
handle, err := client.Acquire(ctx, "my::resource", nil)
if err == accord.ErrDone {
fmt.Println("Resource has been already marked as done")
return
} else if err == accord.ErrAcquired {
fmt.Println("Resource is currently held by another process")
return
} else if err != nil {
panic(err)
}
defer handle.Discard()
// Yay, we have acquired a handle on the resource, now let's do something!
// ...
// When done, we can mark the resource as done.
if err := handle.Done(ctx, nil); err != nil {
panic(err)
}
}
func DialClient ¶
func DialClient(ctx context.Context, target string, opt *ClientOptions, dialOpt ...grpc.DialOption) (*Client, error)
DialClient creates a new client connection.
func WrapClient ¶
func WrapClient(ctx context.Context, cc *grpc.ClientConn, opt *ClientOptions) (*Client, error)
WrapClient inits a new client by wrapping a gRCP client connection.
type ClientOptions ¶
type ClientOptions struct {
Owner string // owner, default: random UUID
Namespace string // namespace, default: ""
Metadata map[string]string // default metadata
TTL time.Duration // TTL, default: 10 minutes
Dir string // Temporary directory, defaults to os.TempDir()
OnError func(error) // custom error handler for background tasks
}
ClientOptions contains options for the client
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle holds temporary ownership of a resource. It will automatically renew its ownership in the background until either Done or Discard is called (first one wins). After a call to Done or Discard, all operations on the handle fail with ErrClosed.
Directories
¶
| Path | Synopsis |
|---|---|
|
direct
Package direct implements a backend wrapper which allows to connect clients to a backend directly bypassing grpc servers.
|
Package direct implements a backend wrapper which allows to connect clients to a backend directly bypassing grpc servers. |
|
mock
Package mock implements an in-memory mock backend for testing.
|
Package mock implements an in-memory mock backend for testing. |
|
postgres
Package postgres implements a postgres-based backend for storing state.
|
Package postgres implements a postgres-based backend for storing state. |
|
cmd
|
|
|
accord-server
command
|
|
|
internal
|
|
Click to show internal directories.
Click to hide internal directories.