github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+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  	if result := <-a.Srv.Store.Job().Get(id); result.Err != nil {
    12  		return nil, result.Err
    13  	} else {
    14  		return result.Data.(*model.Job), nil
    15  	}
    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  	if result := <-a.Srv.Store.Job().GetAllPage(offset, limit); result.Err != nil {
    24  		return nil, result.Err
    25  	} else {
    26  		return result.Data.([]*model.Job), nil
    27  	}
    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  	if result := <-a.Srv.Store.Job().GetAllByTypePage(jobType, offset, limit); result.Err != nil {
    36  		return nil, result.Err
    37  	} else {
    38  		return result.Data.([]*model.Job), nil
    39  	}
    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  }