mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-6595-Server: Job Management APIs. (#6931)
* PLT-6595-Server: Job Management APIs. * MANAGE_JOBS Permission * Fix test.
This commit is contained in:
committed by
Christopher Speller
parent
5ae701d133
commit
6c6f2a1138
21
app/job.go
21
app/job.go
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/jobs"
|
||||
)
|
||||
|
||||
func GetJob(id string) (*model.Job, *model.AppError) {
|
||||
@@ -15,6 +16,18 @@ func GetJob(id string) (*model.Job, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return GetJobs(page*perPage, perPage)
|
||||
}
|
||||
|
||||
func GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
if result := <-Srv.Store.Job().GetAllPage(offset, limit); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.Job), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return GetJobsByType(jobType, page*perPage, perPage)
|
||||
}
|
||||
@@ -26,3 +39,11 @@ func GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.
|
||||
return result.Data.([]*model.Job), nil
|
||||
}
|
||||
}
|
||||
|
||||
func CreateJob(job *model.Job) (*model.Job, *model.AppError) {
|
||||
return jobs.CreateJob(job.Type, job.Data)
|
||||
}
|
||||
|
||||
func CancelJob(jobId string) *model.AppError {
|
||||
return jobs.RequestCancellation(jobId)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/mattermost/platform/store"
|
||||
)
|
||||
|
||||
func TestGetJobStatus(t *testing.T) {
|
||||
func TestGetJob(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
status := &model.Job{
|
||||
@@ -30,7 +30,7 @@ func TestGetJobStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetJobStatusesByType(t *testing.T) {
|
||||
func TestGetJobByType(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
jobType := model.NewId()
|
||||
@@ -39,17 +39,17 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 1000,
|
||||
CreateAt: 1000,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 999,
|
||||
CreateAt: 999,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
StartAt: 1001,
|
||||
CreateAt: 1001,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
} else if received[0].Id != statuses[1].Id {
|
||||
} else if received[0].Id != statuses[2].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")
|
||||
@@ -72,7 +72,7 @@ func TestGetJobStatusesByType(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
} else if received[0].Id != statuses[2].Id {
|
||||
} else if received[0].Id != statuses[1].Id {
|
||||
t.Fatal("should've received oldest job last")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user