Telemetry
This commit is contained in:
parent
82d68be007
commit
56eda6bbdf
2 changed files with 31 additions and 15 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -21,6 +22,7 @@ import (
|
|||
"github.com/mattermost/mattermost-octo-tasks/server/services/webhook"
|
||||
"github.com/mattermost/mattermost-octo-tasks/server/web"
|
||||
"github.com/mattermost/mattermost-octo-tasks/server/ws"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/filesstore"
|
||||
)
|
||||
|
@ -132,15 +134,24 @@ func New(cfg *config.Configuration, singleUser bool) (*Server, error) {
|
|||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
if err := s.webServer.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
httpServerExitDone := &sync.WaitGroup{}
|
||||
httpServerExitDone.Add(1)
|
||||
|
||||
s.webServer.Start(httpServerExitDone)
|
||||
|
||||
s.cleanUpSessionsTask = scheduler.CreateRecurringTask("cleanUpSessions", func() {
|
||||
if err := s.store.CleanUpSessions(s.config.SessionExpireTime); err != nil {
|
||||
s.logger.Error("Unable to clean up the sessions", zap.Error(err))
|
||||
}
|
||||
}, 10*time.Minute)
|
||||
|
||||
if s.config.Telemetry {
|
||||
firstRun := utils.MillisFromTime(time.Now())
|
||||
s.telemetry.RunTelemetryJob(firstRun)
|
||||
}
|
||||
|
||||
httpServerExitDone.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -153,6 +164,8 @@ func (s *Server) Shutdown() error {
|
|||
s.cleanUpSessionsTask.Cancel()
|
||||
}
|
||||
|
||||
s.telemetry.Shutdown()
|
||||
|
||||
return s.store.Shutdown()
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -62,27 +63,29 @@ func (ws *Server) registerRoutes() {
|
|||
}
|
||||
|
||||
// Start runs the web server and start listening for charsetnnections.
|
||||
func (ws *Server) Start() error {
|
||||
func (ws *Server) Start(wg *sync.WaitGroup) {
|
||||
ws.registerRoutes()
|
||||
|
||||
isSSL := ws.ssl && fileExists("./cert/cert.pem") && fileExists("./cert/key.pem")
|
||||
if isSSL {
|
||||
log.Printf("https server started on :%d\n", ws.port)
|
||||
err := ws.ListenAndServeTLS("./cert/cert.pem", "./cert/key.pem")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ws.ListenAndServeTLS("./cert/cert.pem", "./cert/key.pem"); err != nil {
|
||||
log.Fatalf("ListenAndServeTLS: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("http server started on :%d\n", ws.port)
|
||||
err := ws.ListenAndServe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ws.ListenAndServe(); err != http.ErrServerClosed {
|
||||
log.Fatalf("ListenAndServe: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (ws *Server) Shutdown() error {
|
||||
|
|
Loading…
Reference in a new issue