PLT-6408 Framework for job server (#6404)
* Added initial job server * Added job server to be ran as part of platform * Added test job to the enterprise repo * Fixed job server not loading license * Renamed job package to jobs * Fixed TE not being buildable * Added JobStatus table to database * Changed fields used by JobStatus * Added APIs to query job status * Added config change listener to server * Added option to run job server from Makefile * Added ability to enable/disable jobs from config * Commented out placeholder for search indexing job * Fixed govet * Removed debug messages and fixed job api init message
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
920bc0d871
Коммит
577ed27f1b
28
app/job.go
Обычный файл
28
app/job.go
Обычный файл
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func GetJobStatus(id string) (*model.JobStatus, *model.AppError) {
|
||||
if result := <-Srv.Store.JobStatus().Get(id); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.JobStatus), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetJobStatusesByTypePage(jobType string, page int, perPage int) ([]*model.JobStatus, *model.AppError) {
|
||||
return GetJobStatusesByType(jobType, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func GetJobStatusesByType(jobType string, offset int, limit int) ([]*model.JobStatus, *model.AppError) {
|
||||
if result := <-Srv.Store.JobStatus().GetAllByTypePage(jobType, offset, limit); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.JobStatus), nil
|
||||
}
|
||||
}
|
||||
78
app/job_test.go
Обычный файл
78
app/job_test.go
Обычный файл
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
)
|
||||
|
||||
func TestGetJobStatus(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
status := &model.JobStatus{
|
||||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
if result := <-Srv.Store.JobStatus().SaveOrUpdate(status); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
defer Srv.Store.JobStatus().Delete(status.Id)
|
||||
|
||||
if received, err := GetJobStatus(status.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if received.Id != status.Id || received.Status != status.Status {
|
||||
t.Fatal("inccorrect job status received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetJobStatusesByType(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
statuses := []*model.JobStatus{
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 1000,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 999,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 1001,
|
||||
},
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
store.Must(Srv.Store.JobStatus().SaveOrUpdate(status))
|
||||
defer Srv.Store.JobStatus().Delete(status.Id)
|
||||
}
|
||||
|
||||
if received, err := GetJobStatusesByType(jobType, 0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
} else if received[0].Id != statuses[1].Id {
|
||||
t.Fatal("should've received newest job first")
|
||||
} else if received[1].Id != statuses[0].Id {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
|
||||
if received, err := GetJobStatusesByType(jobType, 2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
} else if received[0].Id != statuses[2].Id {
|
||||
t.Fatal("should've received oldest job last")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
@@ -23,28 +22,14 @@ func LoadLicense() {
|
||||
|
||||
if len(licenseId) != 26 {
|
||||
// Lets attempt to load the file from disk since it was missing from the DB
|
||||
fileName := utils.GetLicenseFileLocation(*utils.Cfg.ServiceSettings.LicenseFileLocation)
|
||||
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk()
|
||||
|
||||
if _, err := os.Stat(fileName); err == nil {
|
||||
l4g.Info("License key has not been uploaded. Loading license key from disk at %v", fileName)
|
||||
licenseBytes := utils.GetLicenseFileFromDisk(fileName)
|
||||
|
||||
if success, licenseStr := utils.ValidateLicense(licenseBytes); success {
|
||||
licenseFileFromDisk := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||
licenseId = licenseFileFromDisk.Id
|
||||
if _, err := SaveLicense(licenseBytes); err != nil {
|
||||
l4g.Info("Failed to save license key loaded from disk err=%v", err.Error())
|
||||
return
|
||||
}
|
||||
if license != nil {
|
||||
if _, err := SaveLicense(licenseBytes); err != nil {
|
||||
l4g.Info("Failed to save license key loaded from disk err=%v", err.Error())
|
||||
} else {
|
||||
l4g.Error("Found license key at %v but it appears to be invalid.", fileName)
|
||||
return
|
||||
licenseId = license.Id
|
||||
}
|
||||
|
||||
} else {
|
||||
l4g.Info(utils.T("mattermost.load_license.find.warn"))
|
||||
l4g.Debug("We could not find the license key in the database or on disk at %v", fileName)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user