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