Skip to content

Commit

Permalink
Merge pull request #140 from brotherlogic/mover
Browse files Browse the repository at this point in the history
Wantslist processes client updates. This closes #139
  • Loading branch information
brotherlogic committed Oct 27, 2020
2 parents 29f33a5 + 369e81f commit 4227d74
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 53 deletions.
52 changes: 5 additions & 47 deletions wantslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/brotherlogic/goserver"
"github.com/brotherlogic/keystore/client"
"golang.org/x/net/context"
"google.golang.org/grpc"

Expand Down Expand Up @@ -87,11 +86,11 @@ func (p *prodWantBridge) get(ctx context.Context, id int32) (*pbrw.MasterWant, e
defer conn.Close()

client := pbrw.NewWantServiceClient(conn)
want, err := client.GetWant(ctx, &pbrw.GetWantRequest{ReleaseId: id})
want, err := client.GetWants(ctx, &pbrw.GetWantsRequest{ReleaseId: []int32{id}})
if err != nil {
return nil, err
}
return want.GetWant(), err
return want.GetWant()[0], err
}

//Server main server type
Expand Down Expand Up @@ -160,7 +159,7 @@ func (s *Server) load(ctx context.Context) error {
}

if len(s.config.Lists) != 8 {
s.RaiseIssue(ctx, "Wantlist mismatch", fmt.Sprintf("Only 8 lists allowed, you have %v", len(s.config.Lists)), false)
s.RaiseIssue("Wantlist mismatch", fmt.Sprintf("Only 8 lists allowed, you have %v", len(s.config.Lists)))
}

return nil
Expand All @@ -186,46 +185,7 @@ func (s *Server) Mote(ctx context.Context, master bool) error {

// GetState gets the state of the server
func (s *Server) GetState() []*pbg.State {
unprocCount := int64(0)
wantedCount := int64(0)
unknownCount := int64(0)
total := int64(0)
lowestProcessTime := time.Now().Unix()

str := ""
names := []string{}
for i, list := range s.config.Lists {

names = append(names, list.GetName())
str += fmt.Sprintf("%v -> %v,", i, len(list.Wants))

if list.LastProcessTime < lowestProcessTime {
lowestProcessTime = list.LastProcessTime
}

total += int64(len(list.Wants))
for _, entry := range list.Wants {
switch entry.Status {
case pb.WantListEntry_UNPROCESSED:
unprocCount++
case pb.WantListEntry_WANTED:
wantedCount++
default:
unknownCount++
}
}
}
return []*pbg.State{
&pbg.State{Key: "current_lists", Text: fmt.Sprintf("%v", names)},
&pbg.State{Key: "last_change", TimeValue: s.config.LastChange},
&pbg.State{Key: "strstr", Text: str},
&pbg.State{Key: "lists", Value: int64(len(s.config.Lists))},
&pbg.State{Key: "unproc", Value: unprocCount},
&pbg.State{Key: "wanted", Value: wantedCount},
&pbg.State{Key: "unknown", Value: unknownCount},
&pbg.State{Key: "total", Value: total},
&pbg.State{Key: "last_processed", TimeValue: lowestProcessTime},
}
return []*pbg.State{}
}

func main() {
Expand All @@ -241,14 +201,12 @@ func main() {
server.PrepServer()
server.Register = server

server.GoServer.KSclient = *keystoreclient.GetClient(server.DialMaster)

err := server.RegisterServerV2("wantslist", false, true)
if err != nil {
return
}

server.RegisterLockingTask(server.prodProcess, "process_want_lists")
//server.RegisterLockingTask(server.prodProcess, "process_want_lists")

fmt.Printf("%v", server.Serve())
}
9 changes: 8 additions & 1 deletion wantslistapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"fmt"
"time"

pb "github.com/brotherlogic/wantslist/proto"
"golang.org/x/net/context"

rcpb "github.com/brotherlogic/recordcollection/proto"
pb "github.com/brotherlogic/wantslist/proto"
)

//AddWantList adds a want list
Expand All @@ -25,3 +27,8 @@ func (s *Server) AddWantList(ctx context.Context, req *pb.AddWantListRequest) (*
func (s *Server) GetWantList(ctx context.Context, req *pb.GetWantListRequest) (*pb.GetWantListResponse, error) {
return &pb.GetWantListResponse{Lists: s.config.Lists}, nil
}

//ClientUpdate on an updated record
func (s *Server) ClientUpdate(ctx context.Context, req *rcpb.ClientUpdateRequest) (*rcpb.ClientUpdateResponse, error) {
return &rcpb.ClientUpdateResponse{}, s.prodProcess(ctx)
}
6 changes: 3 additions & 3 deletions wantslistutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import (
pb "github.com/brotherlogic/wantslist/proto"
)

func (s *Server) prodProcess(ctx context.Context) (time.Time, error) {
func (s *Server) prodProcess(ctx context.Context) error {
err := s.load(ctx)
if err == nil {
err = s.processWantLists(ctx, s.listWait)
}
return time.Now().Add(time.Hour), s.processWantLists(ctx, s.listWait)
return s.processWantLists(ctx, s.listWait)
}

func (s *Server) updateWant(ctx context.Context, v *pb.WantListEntry) error {
if v.Status == pb.WantListEntry_WANTED {
r, err := s.rcBridge.getRecord(ctx, v.Want)
s.Log(fmt.Sprintf("GOT Record: %v, %v", r, err))
if err == nil && r.GetMetadata().Category != pbrc.ReleaseMetadata_UNLISTENED && r.GetMetadata().Category != pbrc.ReleaseMetadata_STAGED {
s.RaiseIssue(ctx, "Wantlist Update", fmt.Sprintf("Transition to complete because category is %v", r.GetMetadata().Category), false)
s.RaiseIssue("Wantlist Update", fmt.Sprintf("Transition to complete because category is %v", r.GetMetadata().Category))
v.Status = pb.WantListEntry_COMPLETE
} else if err != nil {
s.Log(fmt.Sprintf("Error record: %v", err))
Expand Down
4 changes: 2 additions & 2 deletions wantslistutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/brotherlogic/keystore/client"
keystoreclient "github.com/brotherlogic/keystore/client"
pbrw "github.com/brotherlogic/recordwants/proto"
"golang.org/x/net/context"

Expand Down Expand Up @@ -75,7 +75,7 @@ func TestFirstEntrySet(t *testing.T) {
},
})

s.prodProcess(context.Background())
s.ClientUpdate(context.Background(), &pbrc.ClientUpdateRequest{})

lists, err := s.GetWantList(context.Background(), &pb.GetWantListRequest{})
if err != nil {
Expand Down

0 comments on commit 4227d74

Please sign in to comment.