From e0f82b0a29e05c27b62def2ef2187c2a7b8f0d5f Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Sat, 26 Mar 2016 17:15:59 -0400 Subject: [PATCH] Data logging graceful shutdown. --- main/datalog.go | 16 +++++++++++----- main/gen_gdl90.go | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/main/datalog.go b/main/datalog.go index 89f8f416..19bcca8f 100644 --- a/main/datalog.go +++ b/main/datalog.go @@ -236,9 +236,11 @@ type DataLogRow struct { } var dataLogChan chan DataLogRow +var shutdownDataLog chan bool func dataLogWriter() { dataLogChan = make(chan DataLogRow, 10240) + shutdownDataLog = make(chan bool) // Check if we need to create a new database. createDatabase := false @@ -266,14 +268,18 @@ func dataLogWriter() { } for { + select { //FIXME: measure latency from here to end of block. Messages may need to be timestamped *before* executing everything here. - r := <-dataLogChan + case r := <-dataLogChan: - // Check if our time bucket has expired or has never been entered. - if !checkTimestamp() || dataLogTimestamp.id == 0 { - insertData(dataLogTimestamp, "timestamp", db) // Updates dataLogTimestamp.id. + // Check if our time bucket has expired or has never been entered. + if !checkTimestamp() || dataLogTimestamp.id == 0 { + insertData(dataLogTimestamp, "timestamp", db) // Updates dataLogTimestamp.id. + } + insertData(r.data, r.tbl, db) + case <-shutdownDataLog: // Received a message on the channel (anything). Graceful shutdown (defer statement). + return } - insertData(r.data, r.tbl, db) } } diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index 22ca1ed2..c197ce18 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -1165,7 +1165,8 @@ func gracefulShutdown() { // Shut down SDRs. sdrKill() //TODO: Any other graceful shutdown functions. - closeReplayLogs() + // Shut down data logging. + shutdownDataLog <- true os.Exit(1) }