Documentation ¶
Overview ¶
Package server provides an HTTP interface for the job queue/scheduler.
Index ¶
Examples ¶
Constants ¶
const MAX_ENQUEUE_DATA_SIZE = 100 * 1024
The maximum data size that can be sent in the body of a HTTP request.
Variables ¶
var DefaultAuthorizer = NewSharedSecretAuthorizer()
var DefaultServer http.Handler
DefaultServer serves every route using the DefaultAuthorizer for authentication.
Functions ¶
func AddUser ¶
AddUser tells the DefaultAuthorizer that a given user and password is allowed to access the API.
func Get ¶
func Get(a Authorizer) http.Handler
Get returns a http.Handler with all routes initialized using the given Authorizer.
Types ¶
type Authorizer ¶
type Authorizer interface { // Authorize returns nil if the user and token are allowed to access the // API, and a rest.Error otherwise. The rest.Error will be returned as the // body of a 401 HTTP response. Authorize(user string, token string) *rest.Error }
The Authorizer interface can be used to authorize a given user and token to access the API.
type CreateJobRequest ¶
type CreateJobRequest struct { Name string `json:"name"` Attempts uint8 `json:"attempts"` Concurrency uint8 `json:"concurrency"` DeliveryStrategy models.DeliveryStrategy `json:"delivery_strategy"` }
CreateJobRequest is a struct of data sent in the body of a request to /v1/jobs
type EnqueueJobRequest ¶
type EnqueueJobRequest struct { // Job data to enqueue. Data json.RawMessage `json:"data"` // The earliest time we can run this job. If not specified, defaults to the // current time. RunAfter types.NullTime `json:"run_after"` // The latest time we can run this job. If not specified, defaults to null // (never expires). ExpiresAt types.NullTime `json:"expires_at"` }
An EnqueueJobRequest is sent in the body of a request to PUT /v1/jobs/:job-name/:job-id.
type JobStatusRequest ¶
type JobStatusRequest struct { // Should be "succeeded" or "failed". Status models.JobStatus `json:"status"` // Attempt is sent to ensure we don't attempt a null write. Attempt *uint8 `json:"attempt"` // pointer to distinguish between null/omitted value and 0. // Retryable indicates whether a failure is retryable. The default is true. // Set to false to avoid retrying a particular failure. Retryable *bool `json:"retryable"` // pointer to distinguish between null value and false. }
The body of a POST request to /v1/jobs/:job-name/:job-id, recording the status of a job.
type RegexpHandler ¶
type RegexpHandler struct {
// contains filtered or unexported fields
}
A RegexpHandler is a simple http.Handler that can match regular expressions for routes.
Example ¶
Output:
func (*RegexpHandler) HandleFunc ¶
func (h *RegexpHandler) HandleFunc(pattern *regexp.Regexp, methods []string, handler func(http.ResponseWriter, *http.Request))
Handler calls the provided HandlerFunc for requests whose URL matches the given pattern and HTTP method. The first matching route will get called.
func (*RegexpHandler) Handler ¶
Handler calls the provided handler for requests whose URL matches the given pattern and HTTP method. The first matching route will get called.
func (*RegexpHandler) ServeHTTP ¶
func (h *RegexpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP checks all registered routes in turn for a match, and calls ServeHTTP on the first matching handler. If no routes match, StatusMethodNotAllowed will be rendered.
type SharedSecretAuthorizer ¶
type SharedSecretAuthorizer struct {
// contains filtered or unexported fields
}
SharedSecretAuthorizer uses an in-memory map of usernames and passwords to authenticate incoming requests.
func NewSharedSecretAuthorizer ¶
func NewSharedSecretAuthorizer() *SharedSecretAuthorizer
NewSharedSecretAuthorizer creates a SharedSecretAuthorizer ready for use.
func (*SharedSecretAuthorizer) AddUser ¶
func (ssa *SharedSecretAuthorizer) AddUser(userId string, password string)
AddUser authorizes a given user and password to access the API.
type UnsafeBypassAuthorizer ¶
type UnsafeBypassAuthorizer struct{}
Use this if you need to bypass the API authorization scheme.