-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
job.go
48 lines (39 loc) · 1.37 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"github.com/mattermost/mattermost-server/model"
)
func (a *App) GetJob(id string) (*model.Job, *model.AppError) {
result := <-a.Srv.Store.Job().Get(id)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Job), nil
}
func (a *App) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) {
return a.GetJobs(page*perPage, perPage)
}
func (a *App) GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) {
result := <-a.Srv.Store.Job().GetAllPage(offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Job), nil
}
func (a *App) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
return a.GetJobsByType(jobType, page*perPage, perPage)
}
func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
result := <-a.Srv.Store.Job().GetAllByTypePage(jobType, offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Job), nil
}
func (a *App) CreateJob(job *model.Job) (*model.Job, *model.AppError) {
return a.Srv.Jobs.CreateJob(job.Type, job.Data)
}
func (a *App) CancelJob(jobId string) *model.AppError {
return a.Srv.Jobs.RequestCancellation(jobId)
}