vspd: Create context and waitgroup near usage.
Creating these closer to where they are needed tidies things up a bit, and reduces the chance of them being used unnecessarily (as was being done previously).
This commit is contained in:
parent
bd41dbee63
commit
350a3f5bb2
@ -51,11 +51,6 @@ func run() int {
|
||||
apiLog := cfg.logger("API")
|
||||
rpcLog := cfg.logger("RPC")
|
||||
|
||||
// Create a context that is cancelled when a shutdown request is received
|
||||
// through an interrupt signal.
|
||||
shutdownCtx := withShutdownCancel(context.Background())
|
||||
go shutdownListener(log)
|
||||
|
||||
// Show version at startup.
|
||||
log.Criticalf("Version %s (Go version %s %s/%s)", version.String(), runtime.Version(),
|
||||
runtime.GOOS, runtime.GOARCH)
|
||||
@ -73,22 +68,26 @@ func run() int {
|
||||
log.Warnf("")
|
||||
}
|
||||
|
||||
// WaitGroup for services to signal when they have shutdown cleanly.
|
||||
var shutdownWg sync.WaitGroup
|
||||
defer log.Criticalf("Shutdown complete")
|
||||
|
||||
// Open database.
|
||||
db, err := database.Open(cfg.dbPath, dbLog, maxVoteChangeRecords)
|
||||
if err != nil {
|
||||
log.Errorf("Database error: %v", err)
|
||||
requestShutdown()
|
||||
shutdownWg.Wait()
|
||||
return 1
|
||||
}
|
||||
|
||||
writeBackup := true
|
||||
defer db.Close(writeBackup)
|
||||
|
||||
// Create a context that is cancelled when a shutdown request is received
|
||||
// through an interrupt signal.
|
||||
shutdownCtx := withShutdownCancel(context.Background())
|
||||
go shutdownListener(log)
|
||||
|
||||
// WaitGroup for services to signal when they have shutdown cleanly.
|
||||
var shutdownWg sync.WaitGroup
|
||||
|
||||
db.WritePeriodicBackups(shutdownCtx, &shutdownWg, cfg.BackupInterval)
|
||||
|
||||
// Create RPC client for local dcrd instance (used for broadcasting and
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user