Skip to content

Commit

Permalink
Move writer to run method
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 6, 2020
1 parent 1232527 commit 0d6e817
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
// Influx is a influx publisher
type Influx struct {
sync.Mutex
log *util.Logger
client influxdb2.Client
writer influxdb2.WriteApi
log *util.Logger
client influxdb2.Client
org string
database string
}

// NewInfluxClient creates new publisher for influx
Expand All @@ -28,20 +29,22 @@ func NewInfluxClient(url, token, org, user, password, database string) *Influx {
}

client := influxdb2.NewClient(url, token)
writer := client.WriteApi(org, database)

return &Influx{
log: log,
client: client,
writer: writer,
log: log,
client: client,
org: org,
database: database,
}
}

// Run Influx publisher
func (m *Influx) Run(in <-chan core.Param) {
writer := m.client.WriteApi(m.org, m.database)

// log errors
go func() {
for err := range m.writer.Errors() {
for err := range writer.Errors() {
m.log.ERROR.Println(err)
}
}()
Expand All @@ -65,7 +68,7 @@ func (m *Influx) Run(in <-chan core.Param) {
)

// write asynchronously
m.writer.WritePoint(p)
writer.WritePoint(p)
}

m.client.Close()
Expand Down

0 comments on commit 0d6e817

Please sign in to comment.