-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.go
104 lines (83 loc) · 2.63 KB
/
admin.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//go:generate go run tools/withoutctx.go
package redash
import (
"context"
"github.com/winebarrel/redash-go/v2/internal/util"
)
type AdminQueriesOutdated struct {
Queries []Query `json:"queries"`
UpdatedAt string `json:"updated_at"`
}
func (client *Client) GetAdminQueriesOutdated(ctx context.Context) (*AdminQueriesOutdated, error) {
res, close, err := client.Get(ctx, "/api/admin/queries/outdated", nil)
defer close()
if err != nil {
return nil, err
}
outdated := &AdminQueriesOutdated{}
if err := util.UnmarshalBody(res, &outdated); err != nil {
return nil, err
}
return outdated, nil
}
type AdminQuerisRqStatus struct {
Queues AdminQuerisRqStatusQueues `json:"queues"`
Workers []AdminQuerisRqStatusWorker `json:"workers"`
}
type AdminQuerisRqStatusQueues struct {
Default *AdminQuerisRqStatusDefault `json:"default"`
Emails *AdminQuerisRqStatusEmails `json:"emails"`
Periodic *AdminQuerisRqStatusPeriodic `json:"periodic"`
Queries *AdminQuerisRqStatusQueries `json:"queries"`
Schemas *AdminQuerisRqStatusSchemas `json:"schemas"`
}
type AdminQuerisRqStatusDefault struct {
Name string `json:"name"`
Queued int `json:"queued"`
Started []any `json:"started"`
}
type AdminQuerisRqStatusEmails struct {
Name string `json:"name"`
Queued int `json:"queued"`
Started []any `json:"started"`
}
type AdminQuerisRqStatusPeriodic struct {
Name string `json:"name"`
Queued int `json:"queued"`
Started []any `json:"started"`
}
type AdminQuerisRqStatusQueries struct {
Name string `json:"name"`
Queued int `json:"queued"`
Started []any `json:"started"`
}
type AdminQuerisRqStatusSchemas struct {
Name string `json:"name"`
Queued int `json:"queued"`
Started []any `json:"started"`
}
type AdminQuerisRqStatusWorker struct {
BirthDate string `json:"birth_date"`
CurrentJob string `json:"current_job"`
FailedJobs int `json:"failed_jobs"`
Hostname string `json:"hostname"`
LastHeartbeat string `json:"last_heartbeat"`
Name string `json:"name"`
Pid int `json:"pid"`
Queues string `json:"queues"`
State string `json:"state"`
SuccessfulJobs int `json:"successful_jobs"`
TotalWorkingTime float64 `json:"total_working_time"`
}
func (client *Client) GetAdminQueriesRqStatus(ctx context.Context) (*AdminQuerisRqStatus, error) {
res, close, err := client.Get(ctx, "/api/admin/queries/rq_status", nil)
defer close()
if err != nil {
return nil, err
}
rqStatus := &AdminQuerisRqStatus{}
if err := util.UnmarshalBody(res, &rqStatus); err != nil {
return nil, err
}
return rqStatus, nil
}