diff options
author | George Goldberg <george@gberg.me> | 2017-07-20 16:25:35 +0100 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-07-20 08:25:35 -0700 |
commit | 6c6f2a1138447777bbf46cc2c40e1b3c47204466 (patch) | |
tree | c2630ad79a7bc12d6c0c0233098e29d6811cb99b /jobs/jobs.go | |
parent | 5ae701d133f713363e52b9cc6aa01579c81ebab4 (diff) | |
download | chat-6c6f2a1138447777bbf46cc2c40e1b3c47204466.tar.gz chat-6c6f2a1138447777bbf46cc2c40e1b3c47204466.tar.bz2 chat-6c6f2a1138447777bbf46cc2c40e1b3c47204466.zip |
PLT-6595-Server: Job Management APIs. (#6931)
* PLT-6595-Server: Job Management APIs.
* MANAGE_JOBS Permission
* Fix test.
Diffstat (limited to 'jobs/jobs.go')
-rw-r--r-- | jobs/jobs.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/jobs/jobs.go b/jobs/jobs.go index 9247355d0..1986b22b6 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -25,6 +25,10 @@ func CreateJob(jobType string, jobData map[string]interface{}) (*model.Job, *mod Data: jobData, } + if err := job.IsValid(); err != nil { + return nil, err + } + if result := <-Srv.Store.Job().Save(&job); result.Err != nil { return nil, result.Err } @@ -41,7 +45,7 @@ func ClaimJob(job *model.Job) (bool, *model.AppError) { } } -func SetJobProgress(job *model.Job, progress int64) (*model.AppError) { +func SetJobProgress(job *model.Job, progress int64) *model.AppError { job.Status = model.JOB_STATUS_IN_PROGRESS job.Progress = progress @@ -78,7 +82,7 @@ func SetJobError(job *model.Job, jobError *model.AppError) *model.AppError { return result.Err } else { if !result.Data.(bool) { - return model.NewAppError("Jobs.SetJobError", "jobs.set_job_error.update.error", nil, "id=" + job.Id, http.StatusInternalServerError) + return model.NewAppError("Jobs.SetJobError", "jobs.set_job_error.update.error", nil, "id="+job.Id, http.StatusInternalServerError) } } } @@ -92,20 +96,20 @@ func SetJobCanceled(job *model.Job) *model.AppError { return result.Err } -func RequestCancellation(job *model.Job) *model.AppError { - if result := <-Srv.Store.Job().UpdateStatusOptimistically(job.Id, model.JOB_STATUS_PENDING, model.JOB_STATUS_CANCELED); result.Err != nil { +func RequestCancellation(jobId string) *model.AppError { + if result := <-Srv.Store.Job().UpdateStatusOptimistically(jobId, model.JOB_STATUS_PENDING, model.JOB_STATUS_CANCELED); result.Err != nil { return result.Err } else if result.Data.(bool) { return nil } - if result := <-Srv.Store.Job().UpdateStatusOptimistically(job.Id, model.JOB_STATUS_IN_PROGRESS, model.JOB_STATUS_CANCEL_REQUESTED); result.Err != nil { + if result := <-Srv.Store.Job().UpdateStatusOptimistically(jobId, model.JOB_STATUS_IN_PROGRESS, model.JOB_STATUS_CANCEL_REQUESTED); result.Err != nil { return result.Err } else if result.Data.(bool) { return nil } - return model.NewAppError("Jobs.RequestCancellation", "jobs.request_cancellation.status.error", nil, "id=" + job.Id, http.StatusInternalServerError) + return model.NewAppError("Jobs.RequestCancellation", "jobs.request_cancellation.status.error", nil, "id="+jobId, http.StatusInternalServerError) } func CancellationWatcher(ctx context.Context, jobId string, cancelChan chan interface{}) { |