-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjob.go
64 lines (57 loc) · 1.58 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package client
// JobStatus represents the status of a job
type JobStatus string
// Job is the set of parameters of a given job
type Job struct {
ID string `json:"id"`
Source string `json:"source"`
Destination string `json:"destination"`
Preset Preset `json:"preset"`
Status JobStatus `json:"status"`
Details string `json:"progress"`
LocalSource string `json:"-"`
LocalDestination string `json:"-"`
}
// JobInput stores the information passed from the
// user when creating a job.
type JobInput struct {
Source string `json:"source"`
Destination string `json:"destination"`
PresetName string `json:"preset"`
}
// GetJobs returns a list of jobs
func (c *Client) GetJobs() ([]Job, error) {
var result []Job
err := c.do("GET", "/jobs", nil, &result)
if err != nil {
return nil, err
}
return result, nil
}
// GetJob returns metadata on a single job
func (c *Client) GetJob(jobID string) (*Job, error) {
var result *Job
err := c.do("GET", "/jobs/"+jobID, nil, &result)
if err != nil {
return nil, err
}
return result, nil
}
// CreateJob sends a single job and send it for processing
func (c *Client) CreateJob(jobInput JobInput) (*Job, error) {
var result *Job
err := c.do("POST", "/jobs", jobInput, &result)
if err != nil {
return nil, err
}
return result, nil
}
// StartJob start a job given a job id
func (c *Client) StartJob(jobID string) (*Job, error) {
var result *Job
err := c.do("POST", "/jobs/"+jobID+"/start", nil, &result)
if err != nil {
return nil, err
}
return result, nil
}