-
Notifications
You must be signed in to change notification settings - Fork 8
/
maintenance.go
79 lines (67 loc) · 2.72 KB
/
maintenance.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
package scalingo
import (
"context"
"time"
"github.com/Scalingo/go-utils/errors/v2"
)
type MaintenanceWindow struct {
WeekdayUTC int `json:"weekday_utc"`
StartingHourUTC int `json:"starting_hour_utc"`
DurationInHour int `json:"duration_in_hour"`
}
type MaintenanceWindowParams struct {
WeekdayUTC *int `json:"weekday_utc,omitempty"`
StartingHourUTC *int `json:"starting_hour_utc,omitempty"`
}
type Maintenance struct {
ID string `json:"id"`
DatabaseID string `json:"database_id"`
Status MaintenanceStatus `json:"status"`
Type string `json:"type"`
StartedAt *time.Time `json:"started_at,omitempty"`
EndedAt *time.Time `json:"ended_at,omitempty"`
}
type MaintenanceStatus string
const (
MaintenanceStatusScheduled MaintenanceStatus = "scheduled"
MaintenanceStatusNotified MaintenanceStatus = "notified"
MaintenanceStatusQueued MaintenanceStatus = "queued"
MaintenanceStatusCancelled MaintenanceStatus = "cancelled"
MaintenanceStatusRunning MaintenanceStatus = "running"
MaintenanceStatusFailed MaintenanceStatus = "failed"
MaintenanceStatusDone MaintenanceStatus = "done"
)
func (c *Client) DatabaseUpdateMaintenanceWindow(ctx context.Context, app, addonID string, params MaintenanceWindowParams) (Database, error) {
var dbRes DatabaseRes
err := c.DBAPI(app, addonID).ResourceUpdate(ctx, "databases", addonID, map[string]interface{}{
"database": map[string]interface{}{
"maintenance_window": params,
},
}, &dbRes)
if err != nil {
return Database{}, errors.Notef(ctx, err, "update database '%v' maintenance window", addonID)
}
return dbRes.Database, nil
}
type ListMaintenanceResponse struct {
Maintenance []*Maintenance `json:"maintenance"`
Meta struct {
PaginationMeta PaginationMeta `json:"pagination"`
}
}
func (c *Client) DatabaseListMaintenance(ctx context.Context, app, addonID string, opts PaginationOpts) ([]*Maintenance, PaginationMeta, error) {
var maintenanceRes ListMaintenanceResponse
err := c.DBAPI(app, addonID).SubresourceList(ctx, "databases", addonID, "maintenance", opts.ToMap(), &maintenanceRes)
if err != nil {
return nil, PaginationMeta{}, errors.Notef(ctx, err, "list database '%v' maintenance", addonID)
}
return maintenanceRes.Maintenance, maintenanceRes.Meta.PaginationMeta, nil
}
func (c *Client) DatabaseShowMaintenance(ctx context.Context, app, addonID, maintenanceID string) (Maintenance, error) {
var maintenanceRes Maintenance
err := c.DBAPI(app, addonID).SubresourceGet(ctx, "databases", addonID, "maintenance", maintenanceID, nil, &maintenanceRes)
if err != nil {
return maintenanceRes, errors.Notef(ctx, err, "get database '%v' maintenance", addonID)
}
return maintenanceRes, nil
}