From 0206303d982e0b6ed209a940674ce43123e968d1 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Mon, 21 Mar 2022 11:28:59 +0100 Subject: [PATCH] Reject jobs if start time is within 24h --- api/rest.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/rest.go b/api/rest.go index ee83b6c..240f41b 100644 --- a/api/rest.go +++ b/api/rest.go @@ -284,15 +284,18 @@ func (api *RestApi) startJob(rw http.ResponseWriter, r *http.Request) { } // Check if combination of (job_id, cluster_id, start_time) already exists: - job, err := api.JobRepository.Find(&req.JobID, &req.Cluster, &req.StartTime) - if err != nil && err != sql.ErrNoRows { + job, err := api.JobRepository.Find(&req.JobID, &req.Cluster, nil) + + if err != nil { handleError(fmt.Errorf("checking for duplicate failed: %w", err), http.StatusInternalServerError, rw) return } if err != sql.ErrNoRows { - handleError(fmt.Errorf("a job with that jobId, cluster and startTime already exists: dbid: %d", job.ID), http.StatusUnprocessableEntity, rw) - return + if (req.StartTime - job.StartTimeUnix) < 86400 { + handleError(fmt.Errorf("a job with that jobId, cluster and startTime already exists: dbid: %d", job.ID), http.StatusUnprocessableEntity, rw) + return + } } id, err := api.JobRepository.Start(&req)