Documentation
¶
Overview ¶
Package qstash holds the reference Queue adapter over Upstash QStash HTTP queues, talking to the REST API directly.
Index ¶
- Constants
- Variables
- func Middleware(keys SigningKeys, url string, next http.Handler) http.Handler
- func Verify(r *http.Request, keys SigningKeys, url string) ([]byte, error)
- func VerifySignature(signature string, body []byte, keys SigningKeys, url string, now time.Time) error
- type Client
- type Options
- type Queue
- type SigningKeys
Constants ¶
const DefaultBaseURL = "https://qstash.upstash.io"
DefaultBaseURL is the QStash API.
const MaxBodyBytes = 1 << 20
MaxBodyBytes caps the body Verify reads. A job is a small JSON ticket.
Variables ¶
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
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
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 (*Queue) Cancel ¶ added in v0.3.0
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 ¶
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.
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.