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 ¶
- Variables
- type Queue
- type QueueServer
- func (qs *QueueServer) AddHandlers()
- func (qs *QueueServer) Close()
- func (qs *QueueServer) GetBaseStore() *store.Store
- func (qs *QueueServer) GetJob(w http.ResponseWriter, r *http.Request)
- func (qs *QueueServer) ListJobs(w http.ResponseWriter, r *http.Request)
- func (qs *QueueServer) Noop(w http.ResponseWriter, r *http.Request)
- func (qs *QueueServer) Queue(w http.ResponseWriter, r *http.Request)
- func (qs *QueueServer) Ready() bool
- func (qs *QueueServer) SetReady()
- func (qs *QueueServer) Start()
- type Record
- type Store
- func (s *Store) GetJob(id string) (*job.Job, error)
- func (s *Store) GetJobStatus(id string) (*job.Status, error)
- func (s *Store) GetRecord(id string) (*Record, error)
- func (s *Store) ListRecords() ([]*Record, error)
- func (s *Store) PutJob(j *job.Job) error
- func (s *Store) PutJobStatus(status *job.Status) error
- type StoreOptions
Constants ¶
This section is empty.
Variables ¶
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) Stop ¶
func (q *Queue) Stop()
Stop drops the relay's subscriptions; the store and client stay open.
func (*Queue) SubscribeJobRequest ¶
SubscribeJobRequest stores every job request and hands it to the workers.
func (*Queue) SubscribeJobStatus ¶
SubscribeJobStatus stores the latest status of every job.
type QueueServer ¶
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) Start ¶
func (qs *QueueServer) Start()
Start installs handlers, starts the relay, and serves until closed.
type 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) GetJobStatus ¶
GetJobStatus returns the latest status of a job, or nil when no worker has reported one yet.
func (*Store) ListRecords ¶
ListRecords returns every stored job with its latest status, oldest first (job IDs are ULIDs, so key order is creation order).
type StoreOptions ¶
type StoreOptions struct {
Location string `json:"location"`
Application string `json:"application"`
Component string `json:"component"`
}
StoreOptions locate the queue store on disk.