Skip to content

Commit c73c552

Browse files
authored
Remove schedule update channel (#30)
* Remove schedule update channel * Remove unused func
1 parent c165018 commit c73c552

File tree

5 files changed

+14
-46
lines changed

5 files changed

+14
-46
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ linters:
3434
- revive
3535
- stylecheck
3636
- unconvert
37+
- unused
3738
- usestdlibvars
3839
- wastedassign
3940
- whitespace

datamodel/common.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package datamodel
22

33
import (
44
"strconv"
5-
"strings"
65
"time"
76
)
87

@@ -120,20 +119,6 @@ func (dm *DataModel) SetPeriodicInformTime(ts time.Time) {
120119
dm.SetValue(pathPeriodicInformTime, ts.UTC().Format(time.RFC3339))
121120
}
122121

123-
// IsPeriodicInformParameter returns true if periodic inform is configured.
124-
func (dm *DataModel) IsPeriodicInformParameter(name string) bool {
125-
if strings.HasSuffix(name, pathPeriodicInformInterval) {
126-
return true
127-
}
128-
if strings.HasSuffix(name, pathPeriodicInformTime) {
129-
return true
130-
}
131-
if strings.HasSuffix(name, pathPeriodicInformEnable) {
132-
return true
133-
}
134-
return false
135-
}
136-
137122
// SetFirmwareVersion sets the new firmware version value.
138123
func (dm *DataModel) SetFirmwareVersion(ver string) {
139124
dm.SetValue(pathSoftwareVersion, ver)

simulator/inform.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func (s *Simulator) periodicInform(ctx context.Context) {
4343
case evt := <-s.pendingEvents:
4444
s.dm.AddEvent(evt)
4545
s.startSession(ctx, s.informHandler)
46-
case <-s.informScheduleUpdate:
4746
case <-s.stop:
4847
return
4948
}
@@ -65,10 +64,6 @@ func (s *Simulator) nextInformTime() time.Time {
6564
)
6665
}
6766

68-
func (s *Simulator) resetInformTimer() {
69-
s.informScheduleUpdate <- struct{}{}
70-
}
71-
7267
// startSession initiates a new session with the ACS.
7368
func (s *Simulator) startSession(ctx context.Context, handler sessionHandler) {
7469
if s.stopped() {

simulator/set_parameter_values.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ func (s *Simulator) handleSetParameterValues(envID string, r *rpc.SetParameterVa
3636
return resp
3737
}
3838

39-
var resetPeriodicInform bool
40-
for _, p := range params {
41-
if s.dm.IsPeriodicInformParameter(p.Path) {
42-
resetPeriodicInform = true
43-
break
44-
}
45-
}
46-
if resetPeriodicInform {
47-
defer s.resetInformTimer()
48-
}
49-
5039
s.metrics.ParametersWritten.Add(float64(len(params)))
5140
s.dm.SetValues(params)
5241
s.dm.SetParameterKey(r.ParameterKey)

simulator/simulator.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ type Simulator struct {
3030
envelopeID uint64
3131
metrics *metrics.Metrics
3232

33-
pendingEvents chan string
34-
pendingRequests chan func(*rpc.EnvelopeEncoder)
35-
informScheduleUpdate chan struct{}
36-
stop chan struct{}
37-
tasks chan taskFn
38-
sessionMux sync.Mutex
33+
pendingEvents chan string
34+
pendingRequests chan func(*rpc.EnvelopeEncoder)
35+
stop chan struct{}
36+
tasks chan taskFn
37+
sessionMux sync.Mutex
3938
}
4039

4140
var errServiceUnavailable = errors.New("service unavailable")
@@ -44,15 +43,14 @@ var errServiceUnavailable = errors.New("service unavailable")
4443
func New(dm *datamodel.DataModel) *Simulator {
4544
jar, _ := cookiejar.New(nil)
4645
return &Simulator{
47-
server: newNoopServer(),
48-
dm: dm,
49-
cookies: jar,
50-
metrics: metrics.NewNoop(),
51-
pendingEvents: make(chan string, 5),
52-
pendingRequests: make(chan func(*rpc.EnvelopeEncoder), 5),
53-
informScheduleUpdate: make(chan struct{}, 1),
54-
stop: make(chan struct{}),
55-
tasks: make(chan taskFn, 5),
46+
server: newNoopServer(),
47+
dm: dm,
48+
cookies: jar,
49+
metrics: metrics.NewNoop(),
50+
pendingEvents: make(chan string, 5),
51+
pendingRequests: make(chan func(*rpc.EnvelopeEncoder), 5),
52+
stop: make(chan struct{}),
53+
tasks: make(chan taskFn, 5),
5654
}
5755
}
5856

0 commit comments

Comments
 (0)