PLT-6916: Redesign the jobs package and Jobserver. (#6733)
This commit redesigns the jobserver to be based around an architecture of "workers", which carry out jobs of a particular type, and "jobs" which are a unit of work carried by a particular worker. It also introduces "schedulers" which are responsible for scheduling jobs of a particular type automatically (jobs can also be scheduled manually when apropriate). Workers may be run many times, either in instances of the platform binary, or the standalone jobserver binary. In any mattermost cluster, only one instance of platform OR jobserver must run the schedulers. At the moment this is controlled by a config variable, but in future will be controlled through the cluster leader election process.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6e0f5f0969
Коммит
0495a51949
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mattermost/platform/jobs"
|
||||
)
|
||||
|
||||
func GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
@@ -187,6 +188,8 @@ func RecycleDatabaseConnection() {
|
||||
l4g.Warn(utils.T("api.admin.recycle_db_start.warn"))
|
||||
Srv.Store = store.NewLayeredStore()
|
||||
|
||||
jobs.Srv.Store = Srv.Store
|
||||
|
||||
time.Sleep(20 * time.Second)
|
||||
oldStore.Close()
|
||||
|
||||
|
||||
16
app/job.go
16
app/job.go
@@ -7,22 +7,22 @@ import (
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func GetJobStatus(id string) (*model.JobStatus, *model.AppError) {
|
||||
if result := <-Srv.Store.JobStatus().Get(id); result.Err != nil {
|
||||
func GetJob(id string) (*model.Job, *model.AppError) {
|
||||
if result := <-Srv.Store.Job().Get(id); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.JobStatus), nil
|
||||
return result.Data.(*model.Job), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetJobStatusesByTypePage(jobType string, page int, perPage int) ([]*model.JobStatus, *model.AppError) {
|
||||
return GetJobStatusesByType(jobType, page*perPage, perPage)
|
||||
func GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return GetJobsByType(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 {
|
||||
func GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
if result := <-Srv.Store.Job().GetAllByTypePage(jobType, offset, limit); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.JobStatus), nil
|
||||
return result.Data.([]*model.Job), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,17 @@ import (
|
||||
func TestGetJobStatus(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
status := &model.JobStatus{
|
||||
status := &model.Job{
|
||||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
if result := <-Srv.Store.JobStatus().SaveOrUpdate(status); result.Err != nil {
|
||||
if result := <-Srv.Store.Job().Save(status); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
defer Srv.Store.JobStatus().Delete(status.Id)
|
||||
defer Srv.Store.Job().Delete(status.Id)
|
||||
|
||||
if received, err := GetJobStatus(status.Id); err != nil {
|
||||
if received, err := GetJob(status.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if received.Id != status.Id || received.Status != status.Status {
|
||||
t.Fatal("inccorrect job status received")
|
||||
@@ -35,7 +35,7 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
statuses := []*model.JobStatus{
|
||||
statuses := []*model.Job{
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
@@ -54,11 +54,11 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
store.Must(Srv.Store.JobStatus().SaveOrUpdate(status))
|
||||
defer Srv.Store.JobStatus().Delete(status.Id)
|
||||
store.Must(Srv.Store.Job().Save(status))
|
||||
defer Srv.Store.Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
if received, err := GetJobStatusesByType(jobType, 0, 2); err != nil {
|
||||
if received, err := GetJobsByType(jobType, 0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
@@ -68,7 +68,7 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
|
||||
if received, err := GetJobStatusesByType(jobType, 2, 2); err != nil {
|
||||
if received, err := GetJobsByType(jobType, 2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
|
||||
Ссылка в новой задаче
Block a user