58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package api
|
|
|
|
// Jobs is used to access the job-specific endpoints.
|
|
type Jobs struct {
|
|
client *Client
|
|
}
|
|
|
|
// Jobs returns a handle on the jobs endpoints.
|
|
func (c *Client) Jobs() *Jobs {
|
|
return &Jobs{client: c}
|
|
}
|
|
|
|
// Register is used to register a new job. It returns the ID
|
|
// of the evaluation, along with any errors encountered.
|
|
func (j *Jobs) Register(job *Job, q *WriteOptions) (string, *WriteMeta, error) {
|
|
var resp registerJobResponse
|
|
|
|
req := ®isterJobRequest{job}
|
|
wm, err := j.client.write("/v1/jobs", req, &resp, q)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
return resp.EvalID, wm, nil
|
|
}
|
|
|
|
// List is used to list all of the existing jobs.
|
|
func (j *Jobs) List() ([]*Job, error) {
|
|
var resp []*Job
|
|
_, err := j.client.query("/v1/jobs", &resp, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
// Job is used to serialize a job.
|
|
type Job struct {
|
|
ID string
|
|
Name string
|
|
Type string
|
|
Priority int
|
|
AllAtOnce bool
|
|
Datacenters []string
|
|
Meta map[string]string
|
|
Status string
|
|
StatusDescription string
|
|
}
|
|
|
|
// registerJobRequest is used to serialize a job registration
|
|
type registerJobRequest struct {
|
|
Job *Job
|
|
}
|
|
|
|
// registerJobResponse is used to deserialize a job response
|
|
type registerJobResponse struct {
|
|
EvalID string
|
|
}
|