Cleanup related to context refactor (#9988)

Этот коммит содержится в:
Christopher Speller
2018-12-17 08:51:46 -08:00
коммит произвёл GitHub
родитель 829f183bb0
Коммит 8429add371
55 изменённых файлов: 1027 добавлений и 949 удалений

Просмотреть файл

@@ -18,6 +18,7 @@ import (
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/utils/fileutils"
)
var ConfigCmd = &cobra.Command{
@@ -89,7 +90,7 @@ func configValidateCmdF(command *cobra.Command, args []string) error {
return err
}
filePath = utils.FindConfigFile(filePath)
filePath = fileutils.FindConfigFile(filePath)
file, err := os.Open(filePath)
if err != nil {

Просмотреть файл

@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/utils/fileutils"
)
func TestConfigFlag(t *testing.T) {
@@ -20,12 +21,12 @@ func TestConfigFlag(t *testing.T) {
defer th.TearDown()
dir := th.TemporaryDirectory()
timezones := utils.LoadTimezones("timezones.json")
timezones := th.App.Timezones.GetSupported()
tzConfigPath := filepath.Join(dir, "timezones.json")
timezoneData, _ := json.Marshal(timezones)
require.NoError(t, ioutil.WriteFile(tzConfigPath, timezoneData, 0600))
i18n, ok := utils.FindDir("i18n")
i18n, ok := fileutils.FindDir("i18n")
require.True(t, ok)
require.NoError(t, utils.CopyDir(i18n, filepath.Join(dir, "i18n")))

Просмотреть файл

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/utils/fileutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -23,7 +24,7 @@ func TestPlugin(t *testing.T) {
os.MkdirAll("./test-plugins", os.ModePerm)
os.MkdirAll("./test-client-plugins", os.ModePerm)
path, _ := utils.FindDir("tests")
path, _ := fileutils.FindDir("tests")
os.Chdir(filepath.Join("..", "..", ".."))

Просмотреть файл

@@ -8,22 +8,16 @@ import (
"os"
"os/signal"
"syscall"
"time"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/manualtesting"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/web"
"github.com/mattermost/mattermost-server/wsapi"
"github.com/spf13/cobra"
)
const (
SESSIONS_CLEANUP_BATCH_SIZE = 1000
)
var serverCmd = &cobra.Command{
Use: "server",
Short: "Run the Mattermost server",
@@ -50,7 +44,10 @@ func serverCmdF(command *cobra.Command, args []string) error {
}
func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
options := []app.Option{app.ConfigFile(configFileLocation)}
options := []app.Option{
app.ConfigFile(configFileLocation),
app.RunJobs,
}
if disableConfigWatch {
options = append(options, app.DisableConfigWatch)
}
@@ -61,69 +58,25 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
}
defer server.Shutdown()
a := server.FakeApp()
if usedPlatform {
mlog.Error("The platform binary has been deprecated, please switch to using the mattermost binary.")
}
serverErr := a.StartServer()
serverErr := server.Start()
if serverErr != nil {
mlog.Critical(serverErr.Error())
return serverErr
}
api := api4.Init(server, server.AppOptions, server.Router)
wsapi.Init(a, server.WebSocketRouter)
wsapi.Init(server.FakeApp(), server.WebSocketRouter)
web.New(server, server.AppOptions, server.Router)
// If we allow testing then listen for manual testing URL hits
if a.Config().ServiceSettings.EnableTesting {
if server.Config().ServiceSettings.EnableTesting {
manualtesting.Init(api)
}
a.Srv.Go(func() {
runSecurityJob(a)
})
a.Srv.Go(func() {
runDiagnosticsJob(a)
})
a.Srv.Go(func() {
runSessionCleanupJob(a)
})
a.Srv.Go(func() {
runTokenCleanupJob(a)
})
a.Srv.Go(func() {
runCommandWebhookCleanupJob(a)
})
if complianceI := a.Compliance; complianceI != nil {
complianceI.StartComplianceDailyJob()
}
if a.Cluster != nil {
a.RegisterAllClusterMessageHandlers()
a.Cluster.StartInterNodeCommunication()
}
if a.Metrics != nil {
a.Metrics.StartServer()
}
if a.Elasticsearch != nil {
a.StartElasticsearch()
}
if *a.Config().JobSettings.RunJobs {
a.Srv.Jobs.StartWorkers()
defer a.Srv.Jobs.StopWorkers()
}
if *a.Config().JobSettings.RunScheduler {
a.Srv.Jobs.StartSchedulers()
defer a.Srv.Jobs.StopSchedulers()
}
notifyReady()
// wait for kill signal before attempting to gracefully shutdown
@@ -131,62 +84,9 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interruptChan
if a.Cluster != nil {
a.Cluster.StopInterNodeCommunication()
}
if a.Metrics != nil {
a.Metrics.StopServer()
}
return nil
}
func runSecurityJob(a *app.App) {
doSecurity(a)
model.CreateRecurringTask("Security", func() {
doSecurity(a)
}, time.Hour*4)
}
func runDiagnosticsJob(a *app.App) {
doDiagnostics(a)
model.CreateRecurringTask("Diagnostics", func() {
doDiagnostics(a)
}, time.Hour*24)
}
func runTokenCleanupJob(a *app.App) {
doTokenCleanup(a)
model.CreateRecurringTask("Token Cleanup", func() {
doTokenCleanup(a)
}, time.Hour*1)
}
func runCommandWebhookCleanupJob(a *app.App) {
doCommandWebhookCleanup(a)
model.CreateRecurringTask("Command Hook Cleanup", func() {
doCommandWebhookCleanup(a)
}, time.Hour*1)
}
func runSessionCleanupJob(a *app.App) {
doSessionCleanup(a)
model.CreateRecurringTask("Session Cleanup", func() {
doSessionCleanup(a)
}, time.Hour*24)
}
func doSecurity(a *app.App) {
a.DoSecurityUpdateCheck()
}
func doDiagnostics(a *app.App) {
if *a.Config().LogSettings.EnableDiagnostics {
a.SendDailyDiagnostics()
}
}
func notifyReady() {
// If the environment vars provide a systemd notification socket,
// notify systemd that the server is ready.
@@ -215,15 +115,3 @@ func sendSystemdReadyNotification(socketPath string) error {
_, err = conn.Write([]byte(msg))
return err
}
func doTokenCleanup(a *app.App) {
a.Srv.Store.Token().Cleanup()
}
func doCommandWebhookCleanup(a *app.App) {
a.Srv.Store.CommandWebhook().Cleanup()
}
func doSessionCleanup(a *app.App) {
a.Srv.Store.Session().Cleanup(model.GetMillis(), SESSIONS_CLEANUP_BATCH_SIZE)
}

Просмотреть файл

@@ -11,7 +11,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/jobs"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/utils/fileutils"
"github.com/stretchr/testify/require"
)
@@ -36,7 +36,7 @@ func SetupServerTest() *ServerTestHelper {
jobs.DEFAULT_WATCHER_POLLING_INTERVAL = 200
th := &ServerTestHelper{
configPath: utils.FindConfigFile("config.json"),
configPath: fileutils.FindConfigFile("config.json"),
disableConfigWatch: true,
interruptChan: interruptChan,
originalInterval: originalInterval,

Просмотреть файл

@@ -53,7 +53,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
defer a.Shutdown()
utils.InitTranslations(a.Config().LocalizationSettings)
serverErr := a.StartServer()
serverErr := a.Srv.Start()
if serverErr != nil {
return serverErr
}
@@ -74,7 +74,7 @@ func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
defer a.Shutdown()
utils.InitTranslations(a.Config().LocalizationSettings)
serverErr := a.StartServer()
serverErr := a.Srv.Start()
if serverErr != nil {
return serverErr
}

Просмотреть файл

@@ -8,7 +8,7 @@ import (
"os"
"syscall"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/utils/fileutils"
)
func main() {
@@ -25,9 +25,9 @@ The platform binary will be removed in a future version.
args[0] = "mattermost"
args = append(args, "--platform")
realMattermost := utils.FindFile("mattermost")
realMattermost := fileutils.FindFile("mattermost")
if realMattermost == "" {
realMattermost = utils.FindFile("bin/mattermost")
realMattermost = fileutils.FindFile("bin/mattermost")
}
if realMattermost == "" {