API Reference
httpclient
import "github.com/danmestas/dagnats/sdk/httpclient"Package httpclient implements the DagNats worker protocol over HTTP. This is the reference client for validating the bridge wire protocol and serves as a template for other language SDKs.
Index
- type Client
- func New(baseURL string, opts …Option) *Client
- func (c *Client) Checkpoint(ctx context.Context, taskID string, data json.RawMessage) error
- func (c *Client) Complete(ctx context.Context, taskID string, output json.RawMessage) error
- func (c *Client) Connect(ctx context.Context, workerID string, taskTypes []string, maxTasks int) error
- func (c *Client) Disconnect()
- func (c *Client) Fail(ctx context.Context, taskID string, errMsg string) error
- func (c *Client) Pause(ctx context.Context, taskID string, name string, duration time.Duration, checkpoint json.RawMessage) error
- func (c *Client) Poll(ctx context.Context, taskTypes []string, maxTasks int, timeout time.Duration) ([]protocol.TaskPayload, error)
- type Option
type Client
Client implements the DagNats worker protocol over HTTP. This is the reference implementation for other language SDKs.
type Client struct {
// contains filtered or unexported fields
}func New
func New(baseURL string, opts ...Option) *ClientNew creates an HTTP client targeting the given base URL. Panics if baseURL is empty.
func (*Client) Checkpoint
func (c *Client) Checkpoint(ctx context.Context, taskID string, data json.RawMessage) errorCheckpoint saves intermediate state for a task.
func (*Client) Complete
func (c *Client) Complete(ctx context.Context, taskID string, output json.RawMessage) errorComplete resolves a task as successfully completed.
func (*Client) Connect
func (c *Client) Connect(ctx context.Context, workerID string, taskTypes []string, maxTasks int) errorConnect registers a worker with the bridge and starts a background SSE heartbeat reader. The SSE connection stays open until Disconnect is called or ctx is cancelled.
func (*Client) Disconnect
func (c *Client) Disconnect()Disconnect cancels the SSE connection.
func (*Client) Fail
func (c *Client) Fail(ctx context.Context, taskID string, errMsg string) errorFail resolves a task as failed with an error message.
func (*Client) Pause
func (c *Client) Pause(ctx context.Context, taskID string, name string, duration time.Duration, checkpoint json.RawMessage) errorPause pauses a task with optional checkpoint, to be resumed after the given duration.
func (*Client) Poll
func (c *Client) Poll(ctx context.Context, taskTypes []string, maxTasks int, timeout time.Duration) ([]protocol.TaskPayload, error)Poll long-polls for available tasks. Returns an empty slice on timeout.
type Option
Option configures a Client.
type Option func(*Client)func WithToken
func WithToken(token string) OptionWithToken sets the bearer token for bridge authentication.
Generated by gomarkdoc