-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrpc.go
More file actions
66 lines (54 loc) · 1.82 KB
/
rpc.go
File metadata and controls
66 lines (54 loc) · 1.82 KB
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
package status
import (
"context"
stderr "errors"
"log/slog"
"connectrpc.com/connect"
statusV2 "github.com/roadrunner-server/api-go/v6/status/v2"
"github.com/roadrunner-server/errors"
)
type rpc struct {
srv *Plugin
log *slog.Logger
}
// connectCodeFor returns CodeNotFound for a missing plugin, CodeInternal otherwise.
func connectCodeFor(err error) connect.Code {
if stderr.Is(err, errPluginNotFound) {
return connect.CodeNotFound
}
return connect.CodeInternal
}
// Status returns the current status of the provided plugin.
func (r *rpc) Status(_ context.Context, req *connect.Request[statusV2.StatusRequest]) (*connect.Response[statusV2.StatusResponse], error) {
const op = errors.Op("checker_rpc_status")
plugin := req.Msg.GetPlugin()
r.log.Debug("Status method was invoked", "plugin", plugin)
st, err := r.srv.status(plugin)
if err != nil {
return nil, connect.NewError(connectCodeFor(err), errors.E(op, err))
}
resp := &statusV2.StatusResponse{}
if st != nil {
resp.Code = int64(st.Code)
r.log.Debug("status code", "code", st.Code)
}
r.log.Debug("successfully finished the Status method")
return connect.NewResponse(resp), nil
}
// Ready returns the readiness check of the provided plugin.
func (r *rpc) Ready(_ context.Context, req *connect.Request[statusV2.StatusRequest]) (*connect.Response[statusV2.StatusResponse], error) {
const op = errors.Op("checker_rpc_ready")
plugin := req.Msg.GetPlugin()
r.log.Debug("Ready method was invoked", "plugin", plugin)
st, err := r.srv.ready(plugin)
if err != nil {
return nil, connect.NewError(connectCodeFor(err), errors.E(op, err))
}
resp := &statusV2.StatusResponse{}
if st != nil {
resp.Code = int64(st.Code)
r.log.Debug("status code", "code", st.Code)
}
r.log.Debug("successfully finished the Ready method")
return connect.NewResponse(resp), nil
}