Skip to content

Commit

Permalink
fix influx connector time freq; fix cid access sync
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed Feb 4, 2019
1 parent 218aec8 commit 2dc89d3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions connectors/influx/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (connector *Connector) Initialize() {
fmt.Println("Error creating InfluxDB Client: ", err.Error())
return
}

connector.running = true
go connector.startPushCycle()

Expand All @@ -45,9 +44,12 @@ func (connector *Connector) Close() {
}

func (connector *Connector) startPushCycle() {
start := time.Now()
for connector.running {
time.Sleep(time.Duration(connector.ExportFreq))
nextRun := start.Add(time.Duration(connector.ExportFreq) * time.Second)
time.Sleep(nextRun.Sub(time.Now()))
connector.push()
start = time.Now()
}
}

Expand Down Expand Up @@ -79,7 +81,16 @@ func (connector *Connector) push() {
connector.pushCounter(counter)
}
for _, counter := range customerCounters {
for cid := range counter.CustomerIndex {
// copy cids
counter.Access.Lock()
cids := make([]string, 0, len(counter.CustomerIndex))
for k := range counter.CustomerIndex {
cids = append(cids, k)
}
counter.Access.Unlock()

// walk through each cid
for _, cid := range cids {
connector.pushCounterCustomer(counter, cid)
}
}
Expand Down

0 comments on commit 2dc89d3

Please sign in to comment.