-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
47 lines (37 loc) · 955 Bytes
/
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
//go:generate go run tools/withoutctx.go
package redash
import (
"context"
"fmt"
"github.com/winebarrel/redash-go/v2/internal/util"
)
const (
// see https://redash.io/help/user-guide/integrations-and-api/api#Jobs
JobStatusPending = 1
JobStatusStarted = 2
JobStatusSuccess = 3
JobStatusFailure = 4
JobStatusCancelled = 5
)
type JobResponse struct {
Job Job `json:"job"`
}
type Job struct {
Error string `json:"error"`
ID string `json:"id"`
QueryResultID int `json:"query_result_id"`
Status int `json:"status"`
UpdatedAt any `json:"updated_at"`
}
func (client *Client) GetJob(ctx context.Context, id string) (*JobResponse, error) {
res, close, err := client.Get(ctx, fmt.Sprintf("api/jobs/%s", id), nil)
defer close()
if err != nil {
return nil, err
}
jobRes := &JobResponse{}
if err := util.UnmarshalBody(res, &jobRes); err != nil {
return nil, err
}
return jobRes, nil
}