Skip to content

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

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) *Client

New 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) error

Checkpoint saves intermediate state for a task.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, taskID string, output json.RawMessage) error

Complete resolves a task as successfully completed.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, workerID string, taskTypes []string, maxTasks int) error

Connect 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) error

Fail 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) error

Pause 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) Option

WithToken sets the bearer token for bridge authentication.

Generated by gomarkdoc