@@ -23,39 +23,31 @@ func (s *server) Push(ctx context.Context, in *hardware.PushRequest) (*hardware.
23
23
// must be a copy so deferred cacheInFlight.Dec matches the Inc
24
24
labels = prometheus.Labels {"method" : "Push" , "op" : "" }
25
25
26
- var h struct {
27
- ID string
28
- State string
29
- }
30
- err := json .Unmarshal ([]byte (in .Data ), & h )
31
- if err != nil {
26
+ hw := in .Data
27
+ if hw .Id == "" {
32
28
metrics .CacheTotals .With (labels ).Inc ()
33
29
metrics .CacheErrors .With (labels ).Inc ()
34
- err = errors .Wrap ( err , "unmarshal json " )
30
+ err : = errors .New ( "id must be set to a UUID " )
35
31
logger .Error (err )
36
32
return & hardware.Empty {}, err
37
33
}
38
34
39
- if h .ID == "" {
40
- metrics .CacheTotals .With (labels ).Inc ()
41
- metrics .CacheErrors .With (labels ).Inc ()
42
- err = errors .New ("id must be set to a UUID" )
43
- logger .Error (err )
44
- return & hardware.Empty {}, err
45
- }
46
-
47
- logger .With ("id" , h .ID ).Info ("data pushed" )
35
+ logger .With ("id" , hw .Id ).Info ("data pushed" )
48
36
49
37
var fn func () error
50
38
msg := ""
51
- if h .State != "deleted" {
39
+ data , err := json .Marshal (hw )
40
+ if err != nil {
41
+ logger .Error (err )
42
+ }
43
+ if hw .Metadata .State != "deleted" {
52
44
labels ["op" ] = "insert"
53
45
msg = "inserting into DB"
54
- fn = func () error { return db .InsertIntoDB (ctx , s .db , in . Data ) }
46
+ fn = func () error { return db .InsertIntoDB (ctx , s .db , string ( data ) ) }
55
47
} else {
56
48
msg = "deleting from DB"
57
49
labels ["op" ] = "delete"
58
- fn = func () error { return db .DeleteFromDB (ctx , s .db , h . ID ) }
50
+ fn = func () error { return db .DeleteFromDB (ctx , s .db , hw . Id ) }
59
51
}
60
52
61
53
metrics .CacheTotals .With (labels ).Inc ()
@@ -75,12 +67,12 @@ func (s *server) Push(ctx context.Context, in *hardware.PushRequest) (*hardware.
75
67
}
76
68
77
69
s .watchLock .RLock ()
78
- if ch := s .watch [h . ID ]; ch != nil {
70
+ if ch := s .watch [hw . Id ]; ch != nil {
79
71
select {
80
- case ch <- in . Data :
72
+ case ch <- string ( data ) :
81
73
default :
82
74
metrics .WatchMissTotal .Inc ()
83
- logger .With ("id" , h . ID ).Info ("skipping blocked watcher" )
75
+ logger .With ("id" , hw . Id ).Info ("skipping blocked watcher" )
84
76
}
85
77
}
86
78
s .watchLock .RUnlock ()
0 commit comments