queue

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 15 Imported by: ? 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 queue is the job relay service: it records every job request and status update in a store and republishes requests to the worker queue, so that job history survives and workers never need to see job.request.*.

Subscribes to:

  • job.request.*.* (stores the job, republishes it with Job.Enqueue)
  • job.status.* (stores the latest status per job)

Publishes to:

  • job.queue.{service}.{name}

QueueServer wraps the relay in an authenticated HTTPS service with a small REST surface for submitting jobs and reading their status. Products that want the bookkeeping run one QueueServer per deployment; products that do not can call Job.Enqueue directly and skip this package.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("queue: job not found")

ErrNotFound is returned when a job ID is unknown to the store.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	Store           *Store
	MessengerClient *messenger.Client
	Logger          *logger.Logger
	// contains filtered or unexported fields
}

Queue is the relay between job requests and the worker queue.

func (*Queue) Start

func (q *Queue) Start() error

Start subscribes to job requests and status updates.

func (*Queue) Stop

func (q *Queue) Stop()

Stop drops the relay's subscriptions; the store and client stay open.

func (*Queue) SubscribeJobRequest

func (q *Queue) SubscribeJobRequest() error

SubscribeJobRequest stores every job request and hands it to the workers.

func (*Queue) SubscribeJobStatus

func (q *Queue) SubscribeJobStatus() error

SubscribeJobStatus stores the latest status of every job.

type QueueServer

type QueueServer struct {
	*server.Server
	// contains filtered or unexported fields
}

QueueServer is the queue relay as an HTTPS service. Build it with NewQueueServer from the usual server.ServerOptions (Messenger must be true) plus Metadata["storeLocation"], then Start it in a routine.

Routes (all bearer-authenticated):

GET  /api/v1/noop        session check
GET  /api/v1/queue       every stored job with its latest status
POST /api/v1/queue       submit a job {service, name, payload}; returns its id
GET  /api/v1/queue/{id}  one job with its latest status

func NewQueueServer

func NewQueueServer(o *server.ServerOptions) (*QueueServer, error)

NewQueueServer builds the server and opens its store.

func (*QueueServer) AddHandlers

func (qs *QueueServer) AddHandlers()

AddHandlers installs middleware and routes and starts the relay.

func (*QueueServer) Close

func (qs *QueueServer) Close()

Close stops the HTTP server, the relay, and the store.

func (*QueueServer) GetBaseStore

func (qs *QueueServer) GetBaseStore() *store.Store

GetBaseStore returns the underlying store for metrics collection.

func (*QueueServer) GetJob

func (qs *QueueServer) GetJob(w http.ResponseWriter, r *http.Request)

GetJob answers one stored job with its latest status.

func (*QueueServer) ListJobs

func (qs *QueueServer) ListJobs(w http.ResponseWriter, r *http.Request)

ListJobs answers every stored job with its latest status.

func (*QueueServer) Noop

func (qs *QueueServer) Noop(w http.ResponseWriter, r *http.Request)

Noop answers 200 for authentication checks and session extension.

func (*QueueServer) Queue

func (qs *QueueServer) Queue(w http.ResponseWriter, r *http.Request)

Queue accepts a job {service, name, payload}, dispatches it, and answers 201 with {"status": "created", "id": ...}.

func (*QueueServer) Ready

func (qs *QueueServer) Ready() bool

Ready reports whether handlers are installed and the relay is running.

func (*QueueServer) SetReady

func (qs *QueueServer) SetReady()

SetReady marks the server ready.

func (*QueueServer) Start

func (qs *QueueServer) Start()

Start installs handlers, starts the relay, and serves until closed.

type Record

type Record struct {
	Job    *job.Job    `json:"job"`
	Status *job.Status `json:"status,omitempty"`
}

Record is a stored job with its latest status, if a worker reported one.

type Store

type Store struct {
	*store.Store
}

Store records every job request and the latest status of each job.

func NewStore

func NewStore(options *StoreOptions) (*Store, error)

NewStore opens (or creates) the queue store.

func (*Store) GetJob

func (s *Store) GetJob(id string) (*job.Job, error)

GetJob returns a stored job request.

func (*Store) GetJobStatus

func (s *Store) GetJobStatus(id string) (*job.Status, error)

GetJobStatus returns the latest status of a job, or nil when no worker has reported one yet.

func (*Store) GetRecord

func (s *Store) GetRecord(id string) (*Record, error)

GetRecord returns a job with its latest status.

func (*Store) ListRecords

func (s *Store) ListRecords() ([]*Record, error)

ListRecords returns every stored job with its latest status, oldest first (job IDs are ULIDs, so key order is creation order).

func (*Store) PutJob

func (s *Store) PutJob(j *job.Job) error

PutJob records a job request.

func (*Store) PutJobStatus

func (s *Store) PutJobStatus(status *job.Status) error

PutJobStatus records the latest status of a job, replacing any earlier one.

type StoreOptions

type StoreOptions struct {
	Location    string `json:"location"`
	Application string `json:"application"`
	Component   string `json:"component"`
}

StoreOptions locate the queue store on disk.

Jump to

Keyboard shortcuts

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