mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 13:29:05 +01:00
Try to fix stop job issue. Add Archive to repo.
This commit is contained in:
parent
d1d6520ab5
commit
9047c69fa6
11
api/rest.go
11
api/rest.go
@ -320,17 +320,13 @@ func (api *RestApi) stopJob(rw http.ResponseWriter, r *http.Request) {
|
|||||||
log.Errorf("archiving job (dbid: %d) failed: %s", job.ID, err.Error())
|
log.Errorf("archiving job (dbid: %d) failed: %s", job.ID, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
api.JobRepository.Archive(job.ID, 0, jobMeta.Statistics)
|
||||||
api.JobRepository.Stop(job.ID, job.Duration, req.State, jobMeta.Statistics)
|
|
||||||
log.Printf("job stopped and archived (dbid: %d)", job.ID)
|
log.Printf("job stopped and archived (dbid: %d)", job.ID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("archiving job... (dbid: %d): cluster=%s, jobId=%d, user=%s, startTime=%s", job.ID, job.Cluster, job.JobID, job.User, job.StartTime)
|
log.Printf("archiving job... (dbid: %d): cluster=%s, jobId=%d, user=%s, startTime=%s", job.ID, job.Cluster, job.JobID, job.User, job.StartTime)
|
||||||
if api.AsyncArchiving {
|
if api.AsyncArchiving {
|
||||||
rw.Header().Add("Content-Type", "application/json")
|
|
||||||
rw.WriteHeader(http.StatusOK)
|
|
||||||
json.NewEncoder(rw).Encode(job)
|
|
||||||
go doArchiving(job, context.Background())
|
go doArchiving(job, context.Background())
|
||||||
} else {
|
} else {
|
||||||
err := doArchiving(job, r.Context())
|
err := doArchiving(job, r.Context())
|
||||||
@ -342,6 +338,11 @@ func (api *RestApi) stopJob(rw http.ResponseWriter, r *http.Request) {
|
|||||||
json.NewEncoder(rw).Encode(job)
|
json.NewEncoder(rw).Encode(job)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.JobRepository.Stop(job.ID, job.Duration, req.State)
|
||||||
|
rw.Header().Add("Content-Type", "application/json")
|
||||||
|
rw.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(rw).Encode(job)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) {
|
func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -78,14 +78,28 @@ 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) {
|
||||||
metricStats map[string]schema.JobStatistics) {
|
|
||||||
|
|
||||||
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 {
|
||||||
|
log.Errorf("Stop job (dbid: %d) failed: %s", jobId, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop updates the job with the database id jobId using the provided arguments.
|
||||||
|
func (r *JobRepository) Archive(
|
||||||
|
jobId int64,
|
||||||
|
monitoringStatus int32,
|
||||||
|
metricStats map[string]schema.JobStatistics) {
|
||||||
|
|
||||||
|
stmt := sq.Update("job").
|
||||||
|
Set("monitoring_status", monitoringStatus).
|
||||||
|
Where("job.id = ?", jobId)
|
||||||
|
|
||||||
for metric, stats := range metricStats {
|
for metric, stats := range metricStats {
|
||||||
switch metric {
|
switch metric {
|
||||||
case "flops_any":
|
case "flops_any":
|
||||||
|
Loading…
Reference in New Issue
Block a user