Add option to opt out of saving device command history. (#640)

This commit is contained in:
Jesse Peterson
2020-01-10 10:55:07 -08:00
committed by GitHub
parent 5c70048c14
commit 05af177cf6
3 changed files with 27 additions and 6 deletions

View File

@@ -25,7 +25,8 @@ const (
type Store struct {
*bolt.DB
logger log.Logger
logger log.Logger
withoutHistory bool
}
type Option func(*Store)
@@ -36,6 +37,12 @@ func WithLogger(logger log.Logger) Option {
}
}
func WithoutHistory() Option {
return func(s *Store) {
s.withoutHistory = true
}
}
func (db *Store) Next(ctx context.Context, resp mdm.Response) ([]byte, error) {
cmd, err := db.nextCommand(ctx, resp)
if err != nil {
@@ -87,8 +94,11 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
if x == nil {
break
}
x.Acknowledged = time.Now().UTC()
dc.Completed = append(dc.Completed, *x)
if !db.withoutHistory {
x.Acknowledged = time.Now().UTC()
dc.Completed = append(dc.Completed, *x)
}
case "Error":
// move to failed, send next
x, a := cut(dc.Commands, resp.CommandUUID)
@@ -96,7 +106,9 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
if x == nil { // must've already bin ackd
break
}
dc.Failed = append(dc.Failed, *x)
if !db.withoutHistory {
dc.Failed = append(dc.Failed, *x)
}
case "CommandFormatError":
// move to failed
@@ -105,7 +117,9 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
if x == nil {
break
}
dc.Failed = append(dc.Failed, *x)
if !db.withoutHistory {
dc.Failed = append(dc.Failed, *x)
}
case "Idle":