Skip to content

Commit

Permalink
Removes config. This closes brotherlogic/keystore#939.
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Oct 29, 2020
1 parent 14f4e39 commit da1bea4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
33 changes: 1 addition & 32 deletions recordprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func (p *prodBridge) print(ctx context.Context, lines []string, move *pbrm.Recor
//Server main server type
type Server struct {
*goserver.GoServer
config *pb.Config
bridge Bridge
count int64
lastCount time.Time
Expand All @@ -212,7 +211,6 @@ type Server struct {
func Init() *Server {
s := &Server{
&goserver.GoServer{},
&pb.Config{},
&prodBridge{},
0,
time.Unix(0, 0),
Expand All @@ -238,43 +236,14 @@ func (s *Server) Shutdown(ctx context.Context) error {
return nil
}

func (s *Server) load(ctx context.Context) error {
config := &pb.Config{}
data, _, err := s.KSclient.Read(ctx, KEY, config)

if err != nil {
return err
}

s.config = data.(*pb.Config)
if s.config.LastPrint == 0 {
return fmt.Errorf("Unable to mote, dodgy data")
}
return nil
}

func (s *Server) save(ctx context.Context) {
s.KSclient.Save(ctx, KEY, s.config)
}

// Mote promotes/demotes this server
func (s *Server) Mote(ctx context.Context, master bool) error {
if master {
return s.load(ctx)
}

return nil
}

// GetState gets the state of the server
func (s *Server) GetState() []*pbg.State {
return []*pbg.State{
&pbg.State{Key: "last_time", TimeValue: s.config.LastPrint},
&pbg.State{Key: "curr_count", Value: s.count},
&pbg.State{Key: "last_count", Text: fmt.Sprintf("%v", s.lastCount)},
&pbg.State{Key: "error", Text: s.lastIssue},
&pbg.State{Key: "curr_print_move", Value: int64(s.currMove)},
}
return []*pbg.State{}
}

func main() {
Expand Down
4 changes: 0 additions & 4 deletions recordprinterutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"time"

"golang.org/x/net/context"

Expand Down Expand Up @@ -97,7 +96,6 @@ func (s *Server) move(ctx context.Context, move *pbrm.RecordMove) error {
// Don't print moves to stale sales
if record.GetMetadata().GetGoalFolder() != 1782105 && move.GetToFolder() != 268147 && move.GetToFolder() != 1708299 {
err = s.bridge.print(ctx, lines, move, true)
s.config.LastPrint = time.Now().Unix()
if err != nil {
return err
}
Expand All @@ -107,8 +105,6 @@ func (s *Server) move(ctx context.Context, move *pbrm.RecordMove) error {
if err != nil {
return err
}

s.save(ctx)
} else {
s.RaiseIssue("Record Print Issue", fmt.Sprintf("Move for %v is not able to be printed", move.GetInstanceId()))
}
Expand Down
17 changes: 14 additions & 3 deletions recordprinterutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

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

pbgd "github.com/brotherlogic/godiscogs"
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestMovePoor(t *testing.T) {
func TestMovePoorContext(t *testing.T) {
s := InitTestServer()
s.bridge = &testBridge{poorContext: true}
s.moveLoop(context.Background(), -1)
s.ClientUpdate(context.Background(), &pbrc.ClientUpdateRequest{InstanceId: -1})
}

func TestMoveFail(t *testing.T) {
Expand Down Expand Up @@ -338,7 +338,18 @@ func TestLocationMove(t *testing.T) {

func TestListeningPileMove(t *testing.T) {
s := InitTestServer()
s.move(context.Background(), &pbrm.RecordMove{BeforeContext: &pbrm.Context{Location: "same"}, AfterContext: &pbrm.Context{Location: "Listening Pile"}})
err := s.move(context.Background(), &pbrm.RecordMove{BeforeContext: &pbrm.Context{Location: "same", BeforeInstance: int32(123), AfterInstance: int32(124)}, AfterContext: &pbrm.Context{Location: "Listening Pile"}})
if err != nil {
t.Errorf("Bad listening pile move: %v", err)
}
}

func TestListeningPileMoveGoneWrong(t *testing.T) {
s := InitTestServer()
err := s.move(context.Background(), &pbrm.RecordMove{BeforeContext: &pbrm.Context{Location: "same"}, AfterContext: &pbrm.Context{Location: "Listening Pile"}})
if err != nil {
t.Errorf("Bad listening pile move: %v", err)
}
}

func TestSekkMove(t *testing.T) {
Expand Down

0 comments on commit da1bea4

Please sign in to comment.