{"modulePath":"github.com/bboxsys/platform","version":"v0.22.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package queue\n\nPackage 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.\\*.\n\nSubscribes to:\n\n  - job.request.\\*.\\*   (stores the job, republishes it with Job.Enqueue)\n  - job.status.\\*      (stores the latest status per job)\n\nPublishes to:\n\n  - job.queue.{service}.{name}\n\nQueueServer 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.\n\n## Variables\n\n```go\nvar ErrNotFound = errors.New(\"queue: job not found\")\n```\nErrNotFound is returned when a job ID is unknown to the store.\n\n## Types\n\n```go\ntype Queue struct {\n\tStore           *Store\n\tMessengerClient *messenger.Client\n\tLogger          *logger.Logger\n\t// contains filtered or unexported fields\n}\n```\nQueue is the relay between job requests and the worker queue.\n\n```go\nfunc (q *Queue) Start() error\n```\nStart subscribes to job requests and status updates.\n\n```go\nfunc (q *Queue) Stop()\n```\nStop drops the relay's subscriptions; the store and client stay open.\n\n```go\nfunc (q *Queue) SubscribeJobRequest() error\n```\nSubscribeJobRequest stores every job request and hands it to the workers.\n\n```go\nfunc (q *Queue) SubscribeJobStatus() error\n```\nSubscribeJobStatus stores the latest status of every job.\n\n```go\ntype QueueServer struct {\n\t*server.Server\n\t// contains filtered or unexported fields\n}\n```\nQueueServer 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.\n\nRoutes (all bearer-authenticated):\n\n\tGET  /api/v1/noop        session check\n\tGET  /api/v1/queue       every stored job with its latest status\n\tPOST /api/v1/queue       submit a job {service, name, payload}; returns its id\n\tGET  /api/v1/queue/{id}  one job with its latest status\n\n```go\nfunc NewQueueServer(o *server.ServerOptions) (*QueueServer, error)\n```\nNewQueueServer builds the server and opens its store.\n\n```go\nfunc (qs *QueueServer) AddHandlers()\n```\nAddHandlers installs middleware and routes and starts the relay.\n\n```go\nfunc (qs *QueueServer) Close()\n```\nClose stops the HTTP server, the relay, and the store.\n\n```go\nfunc (qs *QueueServer) GetBaseStore() *store.Store\n```\nGetBaseStore returns the underlying store for metrics collection.\n\n```go\nfunc (qs *QueueServer) GetJob(w http.ResponseWriter, r *http.Request)\n```\nGetJob answers one stored job with its latest status.\n\n```go\nfunc (qs *QueueServer) ListJobs(w http.ResponseWriter, r *http.Request)\n```\nListJobs answers every stored job with its latest status.\n\n```go\nfunc (qs *QueueServer) Noop(w http.ResponseWriter, r *http.Request)\n```\nNoop answers 200 for authentication checks and session extension.\n\n```go\nfunc (qs *QueueServer) Queue(w http.ResponseWriter, r *http.Request)\n```\nQueue accepts a job {service, name, payload}, dispatches it, and answers 201 with {\"status\": \"created\", \"id\": ...}.\n\n```go\nfunc (qs *QueueServer) Ready() bool\n```\nReady reports whether handlers are installed and the relay is running.\n\n```go\nfunc (qs *QueueServer) SetReady()\n```\nSetReady marks the server ready.\n\n```go\nfunc (qs *QueueServer) Start()\n```\nStart installs handlers, starts the relay, and serves until closed.\n\n```go\ntype Record struct {\n\tJob    *job.Job    `json:\"job\"`\n\tStatus *job.Status `json:\"status,omitempty\"`\n}\n```\nRecord is a stored job with its latest status, if a worker reported one.\n\n```go\ntype Store struct {\n\t*store.Store\n}\n```\nStore records every job request and the latest status of each job.\n\n```go\nfunc NewStore(options *StoreOptions) (*Store, error)\n```\nNewStore opens (or creates) the queue store.\n\n```go\nfunc (s *Store) GetJob(id string) (*job.Job, error)\n```\nGetJob returns a stored job request.\n\n```go\nfunc (s *Store) GetJobStatus(id string) (*job.Status, error)\n```\nGetJobStatus returns the latest status of a job, or nil when no worker has reported one yet.\n\n```go\nfunc (s *Store) GetRecord(id string) (*Record, error)\n```\nGetRecord returns a job with its latest status.\n\n```go\nfunc (s *Store) ListRecords() ([]*Record, error)\n```\nListRecords returns every stored job with its latest status, oldest first (job IDs are ULIDs, so key order is creation order).\n\n```go\nfunc (s *Store) PutJob(j *job.Job) error\n```\nPutJob records a job request.\n\n```go\nfunc (s *Store) PutJobStatus(status *job.Status) error\n```\nPutJobStatus records the latest status of a job, replacing any earlier one.\n\n```go\ntype StoreOptions struct {\n\tLocation    string `json:\"location\"`\n\tApplication string `json:\"application\"`\n\tComponent   string `json:\"component\"`\n}\n```\nStoreOptions locate the queue store on disk.\n\n","path":"github.com/bboxsys/platform/queue","name":"queue","synopsis":"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.*.","isRedistributable":true}
