mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-10-31 16:05:06 +01:00 
			
		
		
		
	Add error handling to stop job
This commit is contained in:
		| @@ -339,10 +339,13 @@ func (api *RestApi) stopJob(rw http.ResponseWriter, r *http.Request) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	api.JobRepository.Stop(job.ID, job.Duration, req.State) | 	err = api.JobRepository.Stop(job.ID, job.Duration, req.State) | ||||||
|  | 	job.State = req.State | ||||||
| 	rw.Header().Add("Content-Type", "application/json") | 	rw.Header().Add("Content-Type", "application/json") | ||||||
| 	rw.WriteHeader(http.StatusOK) | 	rw.WriteHeader(http.StatusOK) | ||||||
| 	json.NewEncoder(rw).Encode(job) | 	json.NewEncoder(rw).Encode(job) | ||||||
|  | 	handleError(fmt.Errorf("Stop job (dbid: %d) failed: %s", job.ID, err.Error()), http.StatusInternalServerError, rw) | ||||||
|  | 	// handleError(fmt.Errorf("archiving failed: %w", err), http.StatusInternalServerError, rw) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) { | func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) { | ||||||
|   | |||||||
| @@ -78,16 +78,15 @@ func (r *JobRepository) Start(job *schema.JobMeta) (id int64, err error) { | |||||||
| func (r *JobRepository) Stop( | func (r *JobRepository) Stop( | ||||||
| 	jobId int64, | 	jobId int64, | ||||||
| 	duration int32, | 	duration int32, | ||||||
| 	state schema.JobState) { | 	state schema.JobState) (err error) { | ||||||
|  |  | ||||||
| 	stmt := sq.Update("job"). | 	stmt := sq.Update("job"). | ||||||
| 		Set("job_state", state). | 		Set("job_state", state). | ||||||
| 		Set("duration", duration). | 		Set("duration", duration). | ||||||
| 		Where("job.id = ?", jobId) | 		Where("job.id = ?", jobId) | ||||||
|  |  | ||||||
| 	if _, err := stmt.RunWith(r.DB).Exec(); err != nil { | 	_, err = stmt.RunWith(r.DB).Exec() | ||||||
| 		log.Errorf("Stop job (dbid: %d) failed: %s", jobId, err.Error()) | 	return | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Stop updates the job with the database id jobId using the provided arguments. | // Stop updates the job with the database id jobId using the provided arguments. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user