mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 13:29:05 +01:00
Allow variable number of parameters for stop job
This commit is contained in:
parent
58afbb2933
commit
9f341a4a6c
@ -212,7 +212,7 @@ func (api *RestApi) startJob(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if combination of (job_id, cluster_id, start_time) already exists:
|
// Check if combination of (job_id, cluster_id, start_time) already exists:
|
||||||
job, err := api.JobRepository.Find(req.JobID, req.Cluster, req.StartTime)
|
job, err := api.JobRepository.Find(&req.JobID, &req.Cluster, &req.StartTime)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
handleError(fmt.Errorf("checking for duplicate failed: %w", err), http.StatusInternalServerError, rw)
|
handleError(fmt.Errorf("checking for duplicate failed: %w", err), http.StatusInternalServerError, rw)
|
||||||
return
|
return
|
||||||
@ -282,12 +282,12 @@ func (api *RestApi) stopJob(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
job, err = api.JobRepository.FindById(id)
|
job, err = api.JobRepository.FindById(id)
|
||||||
} else {
|
} else {
|
||||||
if req.JobId == nil || req.Cluster == nil || req.StartTime == nil {
|
if req.JobId == nil {
|
||||||
handleError(errors.New("the fields 'jobId', 'cluster' and 'startTime' are required"), http.StatusBadRequest, rw)
|
handleError(errors.New("the field 'jobId' is required"), http.StatusBadRequest, rw)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
job, err = api.JobRepository.Find(*req.JobId, *req.Cluster, *req.StartTime)
|
job, err = api.JobRepository.Find(req.JobId, req.Cluster, req.StartTime)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(fmt.Errorf("finding job failed: %w", err), http.StatusUnprocessableEntity, rw)
|
handleError(fmt.Errorf("finding job failed: %w", err), http.StatusUnprocessableEntity, rw)
|
||||||
|
@ -23,13 +23,19 @@ type JobRepository struct {
|
|||||||
// It returns a pointer to a schema.Job data structure and an error variable.
|
// It returns a pointer to a schema.Job data structure and an error variable.
|
||||||
// To check if no job was found test err == sql.ErrNoRows
|
// To check if no job was found test err == sql.ErrNoRows
|
||||||
func (r *JobRepository) Find(
|
func (r *JobRepository) Find(
|
||||||
jobId int64,
|
jobId *int64,
|
||||||
cluster string,
|
cluster *string,
|
||||||
startTime int64) (*schema.Job, error) {
|
startTime *int64) (*schema.Job, error) {
|
||||||
|
|
||||||
qb := sq.Select(schema.JobColumns...).From("job").
|
qb := sq.Select(schema.JobColumns...).From("job").
|
||||||
Where("job.job_id = ?", jobId).
|
Where("job.job_id = ?", jobId)
|
||||||
Where("job.cluster = ?", cluster).
|
|
||||||
Where("job.start_time = ?", startTime)
|
if cluster != nil {
|
||||||
|
qb = qb.Where("job.cluster = ?", *cluster)
|
||||||
|
}
|
||||||
|
if startTime != nil {
|
||||||
|
qb = qb.Where("job.start_time = ?", *startTime)
|
||||||
|
}
|
||||||
|
|
||||||
sqlQuery, args, err := qb.ToSql()
|
sqlQuery, args, err := qb.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user