Skip to content

Commit

Permalink
feat: implement Get interface
Browse files Browse the repository at this point in the history
Signed-off-by: Vigith Maurice <[email protected]>
  • Loading branch information
vigith committed Feb 22, 2025
1 parent 83c0a4c commit 312d16e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
18 changes: 17 additions & 1 deletion pkg/servingstore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ServingStorer interface {
Put(ctx context.Context, put PutRequester)

// Get is to retrieve data from the Serving Store.
Get(ctx context.Context) StoredResults
Get(ctx context.Context, get GetRequester) StoredResults
}

// PutRequester interface exposes methods to retrieve data from the Put rpc.
Expand All @@ -19,6 +19,7 @@ type PutRequester interface {
Payload() [][]byte
}

// PutRequest contains the details to store the payload to the Store.
type PutRequest struct {
origin string
payloads [][]byte
Expand All @@ -33,3 +34,18 @@ func (p *PutRequest) Origin() string {
func (p *PutRequest) Payload() [][]byte {
return p.payloads
}

// GetRequester is the interface to expose methods to retrieve from the Get rpc.
type GetRequester interface {
Id() string
}

// GetRequest has details on the Get rpc.
type GetRequest struct {
id string
}

// Id is the unique ID original request which is used get the data stored in the Store.
func (g *GetRequest) Id() string {
return g.id
}
26 changes: 24 additions & 2 deletions pkg/servingstore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func handlePanic() (err error) {
return err
}

// Put puts tine payload into the Store.
func (s *Service) Put(ctx context.Context, request *servingpb.PutRequest) (*servingpb.PutResponse, error) {
var err error
// handle panic
Expand All @@ -57,11 +58,32 @@ func (s *Service) Put(ctx context.Context, request *servingpb.PutRequest) (*serv
return &servingpb.PutResponse{Success: true}, err
}

// Get gets the data stored in the Store.
func (s *Service) Get(ctx context.Context, request *servingpb.GetRequest) (*servingpb.GetResponse, error) {
//TODO implement me
panic("implement me")
var err error
// handle panic
defer func() { err = handlePanic() }()

storedResults := s.ServingStore.Get(ctx, &GetRequest{id: request.Id})

items := storedResults.Items()
var payloads = make([]*servingpb.OriginalPayload, 0, len(items))

for _, storedResult := range items {
var p = make([]*servingpb.Payload, 0)
for _, payload := range storedResult.payloads {
p = append(p, &servingpb.Payload{Id: request.GetId(), Value: payload.value})
}
payloads = append(payloads, &servingpb.OriginalPayload{
Origin: storedResult.origin,
Payloads: p,
})
}

return &servingpb.GetResponse{Payloads: payloads}, err
}

// IsReady is used to indicate that the server is ready.
func (s *Service) IsReady(_ context.Context, _ *emptypb.Empty) (*servingpb.ReadyResponse, error) {
return &servingpb.ReadyResponse{Ready: true}, nil
}

0 comments on commit 312d16e

Please sign in to comment.