Documentation
¶
Overview ¶
Package client provides a Go client for connecting to a remote Dispatch instance via the Dispatch Wire Protocol (DWP) over WebSocket.
Usage:
c, err := client.Dial("wss://api.example.com/dwp",
client.WithToken("dk_..."),
)
defer c.Close()
// Enqueue a job.
job, err := c.Enqueue(ctx, "send-email", payload)
// Start a workflow and watch events.
run, err := c.StartWorkflow(ctx, "order-pipeline", input)
ch := c.Watch(ctx, run.RunID)
for evt := range ch {
fmt.Printf("Step %s: %s\n", evt.StepName, evt.Type)
}
Index ¶
- type Client
- func (c *Client) CancelJob(ctx context.Context, jobID string) error
- func (c *Client) Close() error
- func (c *Client) Enqueue(ctx context.Context, name string, payload any, opts ...EnqueueOption) (*JobResult, error)
- func (c *Client) GetJob(ctx context.Context, jobID string) (json.RawMessage, error)
- func (c *Client) GetWorkflow(ctx context.Context, runID string) (json.RawMessage, error)
- func (c *Client) PublishEvent(ctx context.Context, name string, payload any) error
- func (c *Client) SessionID() string
- func (c *Client) StartWorkflow(ctx context.Context, name string, input any) (*WorkflowResult, error)
- func (c *Client) Stats(ctx context.Context) (json.RawMessage, error)
- func (c *Client) Subscribe(ctx context.Context, channel string) (<-chan *stream.Event, error)
- func (c *Client) Unsubscribe(ctx context.Context, channel string) error
- func (c *Client) Watch(ctx context.Context, runID string) (<-chan *stream.Event, error)
- type EnqueueOption
- type JobResult
- type Option
- type WorkflowResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a DWP client that communicates with a remote Dispatch server.
func DialContext ¶
DialContext connects to a DWP server with a context.
func (*Client) Enqueue ¶
func (c *Client) Enqueue(ctx context.Context, name string, payload any, opts ...EnqueueOption) (*JobResult, error)
Enqueue submits a job to the remote dispatch server.
func (*Client) GetWorkflow ¶
GetWorkflow retrieves a workflow run by ID.
func (*Client) PublishEvent ¶
PublishEvent publishes an event that can trigger workflow continuations.
func (*Client) StartWorkflow ¶
func (c *Client) StartWorkflow(ctx context.Context, name string, input any) (*WorkflowResult, error)
StartWorkflow starts a workflow on the remote dispatch server.
func (*Client) Subscribe ¶
Subscribe subscribes to a stream topic and returns a channel of events. The channel is closed when the client disconnects or Unsubscribe is called.
Topics follow the dispatch stream convention:
- "job:<jobID>" — Events for a specific job
- "workflow:<runID>" — Step-by-step events for a workflow run
- "queue:<name>" — All events for a queue
- "jobs" — All job lifecycle events
- "workflows" — All workflow lifecycle events
- "firehose" — Everything
func (*Client) Unsubscribe ¶
Unsubscribe removes a subscription.
type EnqueueOption ¶
type EnqueueOption func(*dwp.JobEnqueueRequest)
EnqueueOption configures an enqueue request.
func WithPriority ¶
func WithPriority(priority int) EnqueueOption
WithPriority sets the job priority.
type JobResult ¶
type JobResult struct {
JobID string `json:"job_id"`
Queue string `json:"queue"`
State string `json:"state"`
}
JobResult contains the result of an enqueue operation.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithFormat ¶
WithFormat sets the wire format for frame encoding. Supported values: "json" (default), "msgpack".
func WithReconnect ¶
WithReconnect enables automatic reconnection with the given parameters.
type WorkflowResult ¶
type WorkflowResult struct {
RunID string `json:"run_id"`
Name string `json:"name"`
State string `json:"state"`
}
WorkflowResult contains the result of starting a workflow.