-
Notifications
You must be signed in to change notification settings - Fork 9
/
scheduled_lambdas.go
132 lines (99 loc) · 3.84 KB
/
scheduled_lambdas.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package rockset
import (
"context"
"net/http"
"github.com/rs/zerolog"
rockerr "github.com/rockset/rockset-go-client/errors"
"github.com/rockset/rockset-go-client/openapi"
"github.com/rockset/rockset-go-client/option"
)
// CreateScheduledLambda creates a new scheduled lambda, with optional arguments.
//
// REST API documentation https://docs.rockset.com/documentation/reference/createscheduledlambda
func (rc *RockClient) CreateScheduledLambda(ctx context.Context, workspace, apikey string, cronString string, qlName string,
options ...option.ScheduledLambdaOption) (openapi.ScheduledLambda, error) {
var err error
var httpResp *http.Response
var resp *openapi.ScheduledLambdaResponse
q := rc.ScheduledLambdasApi.CreateScheduledLambda(ctx, workspace)
opts := option.ScheduledLambdaOptions{}
for _, o := range options {
o(&opts)
}
opts.CreateRequest.Apikey = apikey;
opts.CreateRequest.CronString = cronString;
opts.CreateRequest.QlName = qlName;
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Body(opts.CreateRequest).Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return openapi.ScheduledLambda{}, err
}
log := zerolog.Ctx(ctx)
log.Trace().Str("status", httpResp.Status).Msg("scheduled lambda created")
return resp.GetData(), nil
}
// UpdateScheduledLambda updates an existing scheduled lambda, with optional arguments.
//
// REST API documentation https://docs.rockset.com/documentation/reference/updatescheduledlambda
func (rc *RockClient) UpdateScheduledLambda(ctx context.Context, workspace string, scheduledLambdaRRN string,
options ...option.ScheduledLambdaOption) (openapi.ScheduledLambda, error) {
var err error
var httpResp *http.Response
var resp *openapi.ScheduledLambdaResponse
q := rc.ScheduledLambdasApi.UpdateScheduledLambda(ctx, workspace, scheduledLambdaRRN)
opts := option.ScheduledLambdaOptions{}
for _, o := range options {
o(&opts)
}
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Body(opts.UpdateRequest).Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return openapi.ScheduledLambda{}, err
}
log := zerolog.Ctx(ctx)
log.Trace().Str("status", httpResp.Status).Msg("scheduled lambda updated")
return resp.GetData(), nil
}
// DeleteScheduledLambda marks the scheduled lambda for deletion, which will take place in the background. Use the
// WaitUntilScheduledLambdaGone() call to block until the scheduled lambda has been deleted.
//
// REST API documentation https://docs.rockset.com/documentation/reference/deletescheduledlambda
func (rc *RockClient) DeleteScheduledLambda(ctx context.Context, workspace, scheduledLambdaRRN string) error {
var err error
var httpResp *http.Response
q := rc.ScheduledLambdasApi.DeleteScheduledLambda(ctx, workspace, scheduledLambdaRRN)
err = rc.Retry(ctx, func() error {
_, httpResp, err = q.Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return err
}
log := zerolog.Ctx(ctx)
log.Trace().Str("status", httpResp.Status).Msg("scheduled lambda deleted")
return nil
}
// GetScheduledLambda gets details about a scheduled lambda.
//
// REST API documentation https://docs.rockset.com/documentation/reference/getscheduledlambda
func (rc *RockClient) GetScheduledLambda(ctx context.Context, workspace, scheduledLambdaRRN string) (openapi.ScheduledLambda, error) {
var err error
var httpResp *http.Response
var resp *openapi.ScheduledLambdaResponse
log := zerolog.Ctx(ctx)
q := rc.ScheduledLambdasApi.GetScheduledLambda(ctx, workspace, scheduledLambdaRRN)
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return openapi.ScheduledLambda{}, err
}
data := resp.GetData()
log.Debug().Str("RRN", data.GetRrn()).Msg("get scheduled lambda successful")
return data, nil
}