Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implementing different query gen, with more debug outputs
  • Loading branch information
Evan Langlais committed Apr 29, 2019
1 parent 890b527 commit 77a9435
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gateway.go
Expand Up @@ -216,14 +216,18 @@ func (ws *socketConn) handleStatus(updates Packet) {
table = "generator_statuses"
}

var query = ""

if value == 0 {
if _, err := dbConn.Exec("DELETE FROM `sd5-state`.$1 WHERE gen_id = $2 AND status_code = '$3'", table, generatorId, statusCode); err != nil {
fmt.Printf("Error removing status/fault: %v\n", err)
}
query = fmt.Sprintf("DELETE FROM `sd5-state`.%s WHERE gen_id = %d AND status_code = '%s'", table, generatorId, statusCode)
} else {
if _, err := dbConn.Exec("INSERT INTO `sd5-state`.$1 (gen_id, status_code) VALUES ($2, $3) ON DUPLICATE KEY UPDATE gen_id = VALUES(gen_id), status_code = VALUES(status_code)", table, generatorId, statusCode); err != nil {
fmt.Printf("Error setting status/fault: %v\n", err)
}
query = fmt.Sprintf("INSERT INTO `sd5-state`.%s (gen_id, status_code) VALUES (%d, %s) ON DUPLICATE KEY UPDATE gen_id = VALUES(gen_id), status_code = VALUES(status_code)", table, generatorId, statusCode)
}

fmt.Println(query)

if _, err := dbConn.Exec(query); err != nil {
fmt.Printf("Error processing statuses/faults: %v\n", err)
}

var metricData = avro.NewMetricData()
Expand Down

0 comments on commit 77a9435

Please sign in to comment.