Help us shape the future of Go! Take the 2026 Go Developer Survey

queueforge

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package queueforge is a Go client for the QueueForge HTTP API.

Its main feature is safe retries. Enqueue sends an Idempotency-Key (generated automatically when you do not supply one) and reuses the SAME key on every retry, so a retry after a timeout or a 5xx cannot create a duplicate job: the server returns the original job with Idempotent-Replay.

c := queueforge.New("https://queue.example.com", os.Getenv("QUEUEFORGE_KEY"))
job, err := c.Enqueue(ctx, queueforge.EnqueueRequest{TaskType: "email.send", Payload: payload})
done, err := c.Wait(ctx, job.ID, queueforge.WaitOptions{})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConflict

func IsConflict(err error) bool

func IsNotFound

func IsNotFound(err error) bool

IsNotFound / IsConflict are convenience checks for errors.As targets.

Types

type APIError

type APIError struct {
	Status     int
	Code       string
	Message    string
	RequestID  string
	RetryAfter time.Duration
}

APIError is returned for any non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Retryable

func (e *APIError) Retryable() bool

Retryable reports whether repeating the request could succeed.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to one QueueForge deployment. It is safe for concurrent use.

func New

func New(baseURL, apiKey string, opts ...Option) *Client

New creates a client. Requests time out after 30 seconds unless you supply your own http.Client.

func (*Client) Cancel

func (c *Client) Cancel(ctx context.Context, id string) error

Cancel cancels a queued job (or requests cancellation of a running one).

func (*Client) Enqueue

func (c *Client) Enqueue(ctx context.Context, req EnqueueRequest) (*Job, error)

Enqueue submits a job. It retries 429, 5xx and network errors with exponential backoff and full jitter (honouring Retry-After), always with the same idempotency key.

func (*Client) EnqueueBatch

func (c *Client) EnqueueBatch(ctx context.Context, reqs []EnqueueRequest, idempotencyKey string) ([]*Job, error)

EnqueueBatch submits up to 100 jobs atomically: either every job is accepted or none is. Retries (429, 5xx, network) reuse one idempotency key, so a retried batch never creates duplicates. Pass your own idempotencyKey to make separate calls idempotent too; empty means one is generated.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (*Job, error)

Get fetches a job.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string, o WaitOptions) (*Job, error)

Wait polls until the job reaches a terminal state or ctx ends.

type EnqueueRequest

type EnqueueRequest struct {
	TaskType       string          `json:"task_type"`
	Queue          string          `json:"queue,omitempty"`
	Payload        json.RawMessage `json:"payload,omitempty"`
	Priority       *int            `json:"priority,omitempty"`
	RunAt          *time.Time      `json:"run_at,omitempty"`
	MaxAttempts    *int            `json:"max_attempts,omitempty"`
	TimeoutSeconds *int            `json:"timeout_seconds,omitempty"`

	// IdempotencyKey makes submission safe to repeat. Empty = generated for you (and reused across
	// this call's retries). Supply your own to make *separate* calls idempotent too.
	IdempotencyKey string `json:"-"`
	// TraceParent is an optional W3C traceparent header to join an existing trace.
	TraceParent string `json:"-"`
}

EnqueueRequest describes a job to submit.

type Job

type Job struct {
	ID              string          `json:"id"`
	Status          string          `json:"status"`
	TaskType        string          `json:"task_type"`
	Queue           string          `json:"queue"`
	Result          json.RawMessage `json:"result"`
	AttemptsStarted int             `json:"attempts_started"`
	MaxAttempts     int             `json:"max_attempts"`
	LastErrorCode   *string         `json:"last_error_code"`
	LastErrorMsg    *string         `json:"last_error_message"`
	TraceID         string          `json:"trace_id"`
	CreatedAt       time.Time       `json:"created_at"`
	// IdempotentReplay is true when the server recognised the idempotency key and returned the
	// original job instead of creating a new one.
	IdempotentReplay bool `json:"-"`
}

Job is the server's view of a job.

func (*Job) Terminal

func (j *Job) Terminal() bool

Terminal reports whether the job will never change state again (without a replay).

type Option

type Option func(*Client)

Option customises a Client.

func WithBackoff

func WithBackoff(base, max time.Duration) Option

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

func WithMaxRetries

func WithMaxRetries(n int) Option

type WaitOptions

type WaitOptions struct {
	PollInterval time.Duration // default 250ms, growing to 2s
}

WaitOptions controls Wait.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL