Break out usage reporting into a service

This commit is contained in:
Jakob Borg
2015-05-12 09:35:37 +02:00
parent 83ea8dc577
commit c6b2ca8b19
3 changed files with 66 additions and 31 deletions

View File

@@ -485,22 +485,16 @@ func (s *apiSvc) postSystemConfig(w http.ResponseWriter, r *http.Request) {
}
}
// Start or stop usage reporting as appropriate
// Fixup usage reporting settings
if curAcc := cfg.Options().URAccepted; newCfg.Options.URAccepted > curAcc {
// UR was enabled
newCfg.Options.URAccepted = usageReportVersion
newCfg.Options.URUniqueID = randomString(8)
err := sendUsageReport(s.model)
if err != nil {
l.Infoln("Usage report:", err)
}
go usageReportingLoop(s.model)
} else if newCfg.Options.URAccepted < curAcc {
// UR was disabled
newCfg.Options.URAccepted = -1
newCfg.Options.URUniqueID = ""
stopUsageReporting()
}
// Activate and save