From df8fa27ffa596e02d0560aa9238f194911c03e56 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Thu, 13 Jun 2019 23:58:17 -0400 Subject: on SIGINT, push to DB before shutting down also logging elapsed time for DB pulls --- svc/db.go | 5 +++++ svc/init.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/svc/db.go b/svc/db.go index 260c5cc..2156f40 100644 --- a/svc/db.go +++ b/svc/db.go @@ -1,6 +1,9 @@ package svc // import "github.com/getwtxt/getwtxt/svc" import ( + "log" + "time" + "github.com/syndtr/goleveldb/leveldb" "golang.org/x/sys/unix" ) @@ -68,7 +71,9 @@ func pushDB() error { // Reads the database from disk into memory. func pullDB() { + start := time.Now() db := <-dbChan db.pull() dbChan <- db + log.Printf("Database pull took: %v\n", time.Since(start)) } diff --git a/svc/init.go b/svc/init.go index edd081c..b00f45d 100644 --- a/svc/init.go +++ b/svc/init.go @@ -109,8 +109,12 @@ func watchForInterrupt() { go func() { for sigint := range c { - log.Printf("Caught %v. Cleaning up ...\n", sigint) + log.Printf("Caught %v\n", sigint) + log.Printf("Pushing to database ...\n") + pushDB() + + log.Printf("Cleaning up ...\n") killTickers() killDB() -- cgit 1.4.1-2-gfad0