diff --git a/recordprinter.go b/recordprinter.go index 21d7573..f58085c 100644 --- a/recordprinter.go +++ b/recordprinter.go @@ -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 @@ -212,7 +211,6 @@ type Server struct { func Init() *Server { s := &Server{ &goserver.GoServer{}, - &pb.Config{}, &prodBridge{}, 0, time.Unix(0, 0), @@ -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() { diff --git a/recordprinterutils.go b/recordprinterutils.go index 11d8e90..263fe0b 100644 --- a/recordprinterutils.go +++ b/recordprinterutils.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "time" "golang.org/x/net/context" @@ -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 } @@ -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())) } diff --git a/recordprinterutils_test.go b/recordprinterutils_test.go index fcf01fd..71288f7 100644 --- a/recordprinterutils_test.go +++ b/recordprinterutils_test.go @@ -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" @@ -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) { @@ -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) {