qstash

package
v0.14.7 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package qstash holds the reference Queue adapter over Upstash QStash HTTP queues, talking to the REST API directly.

Index

Constants

View Source
const DefaultBaseURL = "https://qstash.upstash.io"

DefaultBaseURL is the QStash API.

View Source
const MaxBodyBytes = 1 << 20

MaxBodyBytes caps the body Verify reads. A job is a small JSON ticket.

Variables

View Source
var ErrInvalidSignature = errors.New("qstash: invalid signature")

ErrInvalidSignature is a request QStash did not sign, or signed for a different URL or body.

Functions

func Middleware added in v0.4.0

func Middleware(keys SigningKeys, url string, next http.Handler) http.Handler

Middleware verifies every request before next sees it, answering 401 to one that fails. next reads the verified body from r.Body as usual.

func Verify added in v0.4.0

func Verify(r *http.Request, keys SigningKeys, url string) ([]byte, error)

Verify checks the Upstash-Signature header of a delivery and returns the body it read. url is the consumer URL QStash was told to call, exactly as passed to Options.URL; it must match the token's subject. The request body is consumed; the returned bytes are the job.

Without this, anyone who learns the consumer URL can post a job that runs any agent under any tenant's state, and bills it.

func VerifySignature added in v0.4.0

func VerifySignature(signature string, body []byte, keys SigningKeys, url string, now time.Time) error

VerifySignature checks one signature against a body. It is Verify without the HTTP request, for a host that reads the body itself.

Types

type Client

type Client struct {
	// Token is the QSTASH_TOKEN.
	Token string
	// BaseURL defaults to DefaultBaseURL.
	BaseURL string
	// HTTP defaults to a client with a 30 second timeout. http.DefaultClient
	// has none, and an enqueue that hangs holds the run that made it.
	HTTP *http.Client
}

Client is the QStash REST client the queue uses.

type Options

type Options struct {
	// URL is the fully-qualified consumer URL, e.g. https://app.example.com/api/queue/agent-run
	URL string
	// QueueName is the queue for flow control (§2.8). Defaults to agent-runs.
	QueueName string
}

Options tune the queue.

type Queue

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

Queue is a Queue over QStash.

func New

func New(client Client, opts Options) *Queue

New makes a queue.

func (*Queue) Cancel added in v0.3.0

func (q *Queue) Cancel(context.Context, string) error

Cancel is a no-op: QStash offers no way to withdraw a queued message by key, and every caller treats a delivered row as a correct no-op.

func (*Queue) Enqueue

func (q *Queue) Enqueue(ctx context.Context, job ports.RunJob, opts *ports.EnqueueOptions) error

Enqueue dispatches a job. A delayed job goes out as a published message rather than a queued one: QStash supports delays on publish only and rejects Upstash-Delay on enqueue. The trade is that this one message skips the queue's flow control, acceptable for the two things that ask for a delay (a HITL expiry and a blocked job's redrive), since both are single messages the run lock already serializes.

func (*Queue) Find added in v0.3.0

Find cannot look a message up; the caller treats this as unknown.

func (*Queue) Stats added in v0.3.0

func (q *Queue) Stats(context.Context) (ports.QueueStats, error)

Stats cannot count; the caller treats this as unknown.

type SigningKeys added in v0.4.0

type SigningKeys struct {
	Current string // QSTASH_CURRENT_SIGNING_KEY
	Next    string // QSTASH_NEXT_SIGNING_KEY
}

SigningKeys are the two keys QStash signs with: the current one, and the next one it rotates to. A request signed with either is accepted.

Jump to

Keyboard shortcuts

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