amboy: Index | Files

package rest

import ""


Package Files

client.go create.go fetch.go job.go service.go stats.go

type Client Uses

type Client struct {
    // contains filtered or unexported fields

Client provides an interface for interacting with a remote amboy Service.

func NewClient Uses

func NewClient(host string, port int, prefix string) (*Client, error)

NewClient takes host, port, and URI prefix information and constructs a new Client.

func NewClientFromExisting Uses

func NewClientFromExisting(client *http.Client, host string, port int, prefix string) (*Client, error)

NewClientFromExisting takes an existing http.Client object and produces a new Client object.

func (*Client) Client Uses

func (c *Client) Client() *http.Client

Client returns a pointer to embedded http.Client object.

func (*Client) Copy Uses

func (c *Client) Copy() *Client

Copy takes an existing Client object and returns a new client object with the same settings that uses a *new* http.Client.

func (*Client) FetchJob Uses

func (c *Client) FetchJob(ctx context.Context, name string) (amboy.Job, error)

FetchJob takes the name of a queue, and returns if possible a representation of that job object.

func (*Client) Host Uses

func (c *Client) Host() string

Host returns the current host.

func (*Client) JobComplete Uses

func (c *Client) JobComplete(ctx context.Context, name string) (bool, error)

JobComplete checks the stats of a job, by name, and returns true if that job is complete. When false, check the second return value to ensure that the job exists in the remote queue.

func (*Client) PendingJobs Uses

func (c *Client) PendingJobs(ctx context.Context) (int, error)

PendingJobs reports on the total number of jobs currently dispatched by the queue to workers.

func (*Client) Port Uses

func (c *Client) Port() int

Port returns the current port value for the Client.

func (*Client) Prefix Uses

func (c *Client) Prefix() string

Prefix accesses the prefix for the client, The prefix is the part of the URI between the end-point and the hostname, of the API.

func (*Client) Running Uses

func (c *Client) Running(ctx context.Context) (bool, error)

Running is true when the underlying queue is running and accepting jobs, and false when the queue is not runner or if there's a problem connecting to the queue.

func (*Client) SetHost Uses

func (c *Client) SetHost(h string) error

SetHost allows callers to change the hostname (including leading "http(s)") for the Client. Returns an error if the specified host does not start with "http".

func (*Client) SetPort Uses

func (c *Client) SetPort(p int) error

SetPort allows callers to change the port used for the client. If the port is invalid, returns an error and sets the port to the default value. (3000)

func (*Client) SetPrefix Uses

func (c *Client) SetPrefix(p string) error

SetPrefix allows callers to modify the prefix, for this client,

func (*Client) SubmitJob Uses

func (c *Client) SubmitJob(ctx context.Context, j amboy.Job) (string, error)

SubmitJob adds a job to a remote queue connected to the rest interface.

func (*Client) Wait Uses

func (c *Client) Wait(ctx context.Context, name string) bool

Wait blocks until the job identified by the name argument is complete. Does not handle the case where a job does not exist.

func (*Client) WaitAll Uses

func (c *Client) WaitAll(ctx context.Context) bool

WaitAll waits for *all* pending jobs in the queue to complete.

type Service Uses

type Service struct {
    // contains filtered or unexported fields

Service is used as a place holder for application state and configuration.

func NewService Uses

func NewService() *Service

NewService constructs a new service object. Use the Open() method to initialize the service, and the Run() method to start the service. The Open and OpenInfo methods configure an embedded amboy Queue; if you use SetQueue you do not need to call

func (*Service) App Uses

func (s *Service) App() *gimlet.APIApp

App provides access to the gimplet.APIApp instance which builds and orchestrates the REST API. Use this method if you want to combine the routes in this Service with another service, or add additional routes to support other application functionality.

func (*Service) Close Uses

func (s *Service) Close()

Close releases resources (i.e. the queue) associated with the service. If you've used SetQueue to define the embedded queue, rather than Open/OpenInfo,

func (*Service) Create Uses

func (s *Service) Create(w http.ResponseWriter, r *http.Request)

Create provides an interface for REST clients to create jobs in the local queue that backs the service.

func (*Service) Fetch Uses

func (s *Service) Fetch(w http.ResponseWriter, r *http.Request)

Fetch is an http handler that writes a job interchange object to a the response, and allows clients to retrieve jobs from the service.

func (*Service) JobStatus Uses

func (s *Service) JobStatus(w http.ResponseWriter, r *http.Request)

JobStatus is a http.HandlerFunc that writes a job status document to the request.

func (*Service) Open Uses

func (s *Service) Open(ctx context.Context) error

Open populates the application and starts the underlying queue. This method sets and initializes a LocalLimitedSize queue implementation, with 2 workers and storage for 256 jobs. Use OpenInfo to have more control over the embedded queue. Use the Close() method on the service to terminate the queue.

func (*Service) OpenInfo Uses

func (s *Service) OpenInfo(ctx context.Context, info ServiceInfo) error

OpenInfo makes it possible to configure the underlying queue in a service. Use the Close() method on the service to terminate the queue.

func (*Service) Queue Uses

func (s *Service) Queue() amboy.Queue

Queue provides access to the underlying queue object for the service.

func (*Service) SetQueue Uses

func (s *Service) SetQueue(q amboy.Queue) error

SetQueue allows callers to inject an alternate queue implementation.

func (*Service) Status Uses

func (s *Service) Status(w http.ResponseWriter, r *http.Request)

Status defines an http.HandlerFunc that returns health check and current staus status information for the entire service.

func (*Service) WaitAll Uses

func (s *Service) WaitAll(w http.ResponseWriter, r *http.Request)

WaitAll blocks waiting for all pending jobs in the queue to stop. Has a default timeout of 10 seconds, and returns 408 (request timeout) when the timeout succeeds.

func (*Service) WaitJob Uses

func (s *Service) WaitJob(w http.ResponseWriter, r *http.Request)

WaitJob waits for a single job to be complete. It takes a timeout argument, which defaults to 10 seconds, and returns 408 (request timeout) if the timeout is reached before the job completes.

type ServiceInfo Uses

type ServiceInfo struct {
    // ForceTimeout makes it possible to control how long to wait
    // for pending jobs to complete before canceling existing
    // work. If this value is zeroed, the Open operation will
    // close the previous queue and start a new queue, otherwise
    // it will attempt to wait for the specified time before closing
    // the previous queue.
    ForceTimeout time.Duration `bson:"force_timeout,omitempty" json:"force_timeout,omitempty" yaml:"force_timeout,omitempty"`

    // The default queue constructed by Open/OpenWith retains a
    // limited number of completed jobs to avoid unbounded memory
    // growth. This value *must* be specified.
    QueueSize int `bson:"queue_size" json:"queue_size" yaml:"queue_size"`

    // Controls the maximum number of go routines that can service
    // jobs in a queue.
    NumWorkers int `bson:"num_workers" json:"num_workers" yaml:"num_workers"`

ServiceInfo provides a way to configure resources allocated by a service.

Package rest imports 13 packages (graph) and is imported by 4 packages. Updated 2018-06-17. Refresh now. Tools for package owners.