Skip to content

Commit

Permalink
Merge pull request #465 from vitessio/custom-run-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
frouioui authored Oct 17, 2023
2 parents cb111a5 + c161cff commit 3f6bda5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
9 changes: 9 additions & 0 deletions go/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,12 @@ func ExistsMacrobenchmarkStartedToday(client storage.SQLClient, gitRef, source,
}
return false, nil
}

func DeleteExecution(client storage.SQLClient, gitRef, UUID, source string) error {
query := fmt.Sprintf("DELETE FROM execution WHERE uuid LIKE '%%%s%%' AND git_ref LIKE '%%%s%%' AND source = '%s'", UUID, gitRef, source)
_, err := client.Select(query)
if err != nil {
return err
}
return nil
}
40 changes: 39 additions & 1 deletion go/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,48 @@ func (s *Server) requestRun(c *gin.Context) {
}

// create execution element
elem := s.createSimpleExecutionQueueElement(cfg, "custom_run", sha, benchmarkType, "", false, 0, currVersion)
elem := s.createSimpleExecutionQueueElement(cfg, "custom_run", sha, benchmarkType, string(macrobench.Gen4Planner), false, 0, currVersion)

// to new element to the queue
s.addToQueue(elem)

c.JSON(http.StatusCreated, "created")
}

func (s *Server) deleteRun(c *gin.Context) {
uuid := c.Query("uuid")
sha := c.Query("sha")
pswd := c.Query("key")

errStrFmt := "missing argument: %s"
if uuid == "" {
errStr := fmt.Sprintf(errStrFmt, "uuid")
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: errStr})
slog.Error(errStr)
return
}

if sha == "" {
errStr := fmt.Sprintf(errStrFmt, "sha")
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: errStr})
slog.Error(errStr)
return
}

// check request run key is correct
if pswd != s.requestRunKey {
errStr := "unauthorized, wrong key"
c.JSON(http.StatusUnauthorized, &ErrorAPI{Error: errStr})
slog.Error(errStr)
return
}

err := exec.DeleteExecution(s.dbClient, sha, uuid, "custom_run")
if err != nil {
c.JSON(http.StatusInternalServerError, &ErrorAPI{Error: err.Error()})
slog.Error(err)
return
}
c.JSON(http.StatusOK, "deleted")
}

1 change: 1 addition & 0 deletions go/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func (s *Server) Run() error {
s.router.GET("/api/daily", s.getDaily)
s.router.GET("/api/status/stats", s.getStatusStats)
s.router.GET("/api/run/request", s.requestRun)
s.router.GET("/api/run/delete", s.deleteRun)

return s.router.Run(":" + s.port)
}
Expand Down

0 comments on commit 3f6bda5

Please sign in to comment.