-
Notifications
You must be signed in to change notification settings - Fork 7
/
jobs.go
42 lines (33 loc) · 912 Bytes
/
jobs.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
package appoptics
import "fmt"
// Job is the representation of a task happening in the AppOptics cloud
type Job struct {
ID int `json:"id"`
State string `json:"state"`
Progress float64 `json:"progress,omitempty"`
Output string `json:"output,omitempty"`
Errors map[string][]string `json:"errors,omitempty"`
}
type JobsCommunicator interface {
Retrieve(int) (*Job, error)
}
type JobsService struct {
client *Client
}
func NewJobsService(c *Client) *JobsService {
return &JobsService{c}
}
// Retrieve gets the Job identified by the provided ID
func (js *JobsService) Retrieve(id int) (*Job, error) {
path := fmt.Sprintf("jobs/%d", id)
req, err := js.client.NewRequest("GET", path, nil)
if err != nil {
return nil, err
}
job := &Job{}
_, err = js.client.Do(req, job)
if err != nil {
return nil, err
}
return job, nil
}